Пример #1
0
  private static void print(StringBuilder builder, Tree node, String prefix, boolean isTail) {
    final String name =
        node.getText() == null ? "" : node.getText().replaceAll("\r\n|\r|\n", "\u23CE");

    builder
        .append(prefix)
        .append(isTail ? "└─ " : "├─ ") //
        .append(String.format("%04d", node.getLine())) //
        .append(':')
        .append(String.format("%04d", node.getCharPositionInLine()))
        .append(' ') //
        .append(String.format("%02d", node.getType()))
        .append(": ")
        .append(name) //
        .append("\n");

    for (int i = 0; i < (node.getChildCount() - 1); i++) {
      CommonTreePrinter.print(
          builder, node.getChild(i), prefix + (isTail ? "    " : "│   "), false);
    }

    if (node.getChildCount() >= 1) {
      CommonTreePrinter.print(
          builder,
          node.getChild(node.getChildCount() - 1),
          prefix + (isTail ? "    " : "│   "),
          true);
    }
  }
Пример #2
0
 @Override
 public int getCharPositionInLine() {
   int col = 0;
   if (token != null) {
     col = token.getCharPositionInLine();
   }
   if (col == 0) {
     Tree child = getChild(0);
     if (child != null) {
       col = child.getCharPositionInLine();
     }
   }
   return col;
 }
Пример #3
0
  public FilteredTreeNodeStream(Tree tree, Filter f) {
    this.tokenizer = new FilteringTokenizer(tree);

    final boolean success = new BracketedFilter(f).filter(this.tokenizer);

    if (success) {
      this.tokens = new ArrayList<Tree>(this.tokenizer.getConsumedTokens());

      if (DEBUG) {
        for (Tree t : this.tokens) {
          System.out.println(
              "--> " + t + "; line " + t.getLine() + ", char " + t.getCharPositionInLine());
        }
      }

    } else {
      // TODO Flag the mismatch somehow.
      this.tokens = new ArrayList<Tree>(0);
    }
  }