コード例 #1
0
ファイル: BaseRascalREPL.java プロジェクト: aruntezz/rascal
  private void printResult(IRascalResult result) throws IOException {
    if (result == null) {
      return;
    }
    PrintWriter out = getOutputWriter();
    IValue value = result.getValue();
    if (value == null) {
      out.println("ok");
      out.flush();
      return;
    }
    Type type = result.getType();

    if (type.isAbstractData() && type.isStrictSubtypeOf(RascalValueFactory.Tree)) {
      out.print(type.toString());
      out.print(": ");
      // we unparse the tree
      out.print("(" + type.toString() + ") `");
      TreeAdapter.yield((IConstructor) result.getValue(), true, out);
      out.print("`");
    } else {
      out.print(type.toString());
      out.print(": ");
      // limit both the lines and the characters
      try (Writer wrt = new LimitedWriter(new LimitedLineWriter(out, LINE_LIMIT), CHAR_LIMIT)) {
        indentedPrettyPrinter.write(value, wrt);
      } catch (IOLimitReachedException e) {
        // ignore since this is what we wanted
      }
    }
    out.println();
    out.flush();
  }
コード例 #2
0
 public String toString() {
   return StandardTextWriter.valueToString(this);
 }