Interface ParseTree
- All Superinterfaces:
SyntaxTree,Tree
- All Known Subinterfaces:
ErrorNode,RuleNode,TerminalNode
- All Known Implementing Classes:
ErrorNodeImpl,InterpreterRuleContext,ParserRuleContext,RuleContext,RuleContextWithAltNum,TerminalNodeImpl
An interface to access the tree of
RuleContext objects created
during a parse that makes the data structure look like a simple parse tree.
This node represents both internal nodes, rule invocations,
and leaf nodes, token matches.
The payload is either a Token or a RuleContext object.
-
Method Summary
Modifier and TypeMethodDescription<T> Taccept(ParseTreeVisitor<? extends T> visitor) TheParseTreeVisitorneeds a double dispatch method.getChild(int i) If there are children, get theith value indexed from 0.The parent of this node.getText()Return the combined text of all leaf nodes.voidsetParent(RuleContext parent) Set the parent for this node.toStringTree(Parser parser) Specialize toStringTree so that it can print out more information based upon the parser.Methods inherited from interface org.graalvm.shadowed.org.antlr.v4.runtime.tree.SyntaxTree
getSourceIntervalMethods inherited from interface org.graalvm.shadowed.org.antlr.v4.runtime.tree.Tree
getChildCount, getPayload, toStringTree
-
Method Details
-
getParent
-
getChild
-
setParent
Set the parent for this node. This is not backward compatible as it changes the interface but no one was able to create custom nodes anyway so I'm adding as it improves internal code quality. One could argue for a restructuring of the class/interface hierarchy so that setParent, addChild are moved up to Tree but that's a major change. So I'll do the minimal change, which is to add this method.- Since:
- 4.7
-
accept
TheParseTreeVisitorneeds a double dispatch method. -
getText
String getText()Return the combined text of all leaf nodes. Does not get any off-channel tokens (if any) so won't return whitespace and comments if they are sent to parser on hidden channel. -
toStringTree
-