/** Converts this node into a {@link ParseTree} representation. */ ParseTree toParseTree() { List<ParseTree> children = new ArrayList<ParseTree>(); for (TreeNode child = latestChild; child != null; child = child.previous) { children.add(child.toParseTree()); } Collections.reverse(children); return new ParseTree(name, beginIndex, endIndex, result, children); }
final ParseTree buildParseTree() { TreeNode currentNode = trace.getCurrentNode(); if (currentNode == null) return null; return currentNode.freeze(getIndex()).toParseTree(); }
final ParseTree buildErrorParseTree() { // The current node is partially done because there was an error. // So orphanize it. But at the same time, all ancestor nodes should have their endIndex set to // where we are now. if (currentErrorNode == null) return null; return currentErrorNode.orphanize().freeze(getIndex()).toParseTree(); }