Package org.antlr.v4.runtime.tree
Class TerminalNodeImpl
- java.lang.Object
-
- org.antlr.v4.runtime.tree.TerminalNodeImpl
-
- All Implemented Interfaces:
ParseTree
,SyntaxTree
,TerminalNode
,Tree
- Direct Known Subclasses:
ErrorNodeImpl
public class TerminalNodeImpl extends Object implements TerminalNode
-
-
Constructor Summary
Constructors Constructor Description TerminalNodeImpl(Token symbol)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
accept(ParseTreeVisitor<? extends T> visitor)
TheParseTreeVisitor
needs a double dispatch method.ParseTree
getChild(int i)
If there are children, get thei
th value indexed from 0.int
getChildCount()
How many children are there? If there is none, then this node represents a leaf node.ParseTree
getParent()
The parent of this node.Token
getPayload()
This method returns whatever object represents the data at this node.Interval
getSourceInterval()
Return anInterval
indicating the index in theTokenStream
of the first and last token associated with this subtree.Token
getSymbol()
String
getText()
Return the combined text of all leaf nodes.void
setParent(RuleContext parent)
Set the parent for this node.String
toString()
String
toStringTree()
Print out a whole tree, not just a node, in LISP format(root child1 .. childN)
.String
toStringTree(Parser parser)
Specialize toStringTree so that it can print out more information based upon the parser.
-
-
-
Constructor Detail
-
TerminalNodeImpl
public TerminalNodeImpl(Token symbol)
-
-
Method Detail
-
getChild
public ParseTree getChild(int i)
Description copied from interface:Tree
If there are children, get thei
th value indexed from 0.
-
getSymbol
public Token getSymbol()
- Specified by:
getSymbol
in interfaceTerminalNode
-
getParent
public ParseTree getParent()
Description copied from interface:Tree
The parent of this node. If the return value is null, then this node is the root of the tree.
-
setParent
public void setParent(RuleContext parent)
Description copied from interface:ParseTree
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.
-
getPayload
public Token getPayload()
Description copied from interface:Tree
This method returns whatever object represents the data at this node. For example, for parse trees, the payload can be aToken
representing a leaf node or aRuleContext
object representing a rule invocation. For abstract syntax trees (ASTs), this is aToken
object.- Specified by:
getPayload
in interfaceTree
-
getSourceInterval
public Interval getSourceInterval()
Description copied from interface:SyntaxTree
Return anInterval
indicating the index in theTokenStream
of the first and last token associated with this subtree. If this node is a leaf, then the interval represents a single token and has interval i..i for token index i.An interval of i..i-1 indicates an empty interval at position i in the input stream, where 0 <= i <= the size of the input token stream. Currently, the code base can only have i=0..n-1 but in concept one could have an empty interval after EOF.
If source interval is unknown, this returns
Interval.INVALID
.As a weird special case, the source interval for rules matched after EOF is unspecified.
- Specified by:
getSourceInterval
in interfaceSyntaxTree
-
getChildCount
public int getChildCount()
Description copied from interface:Tree
How many children are there? If there is none, then this node represents a leaf node.- Specified by:
getChildCount
in interfaceTree
-
accept
public <T> T accept(ParseTreeVisitor<? extends T> visitor)
Description copied from interface:ParseTree
TheParseTreeVisitor
needs a double dispatch method.
-
getText
public String getText()
Description copied from interface:ParseTree
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
public String toStringTree(Parser parser)
Description copied from interface:ParseTree
Specialize toStringTree so that it can print out more information based upon the parser.- Specified by:
toStringTree
in interfaceParseTree
-
toStringTree
public String toStringTree()
Description copied from interface:Tree
Print out a whole tree, not just a node, in LISP format(root child1 .. childN)
. Print just a node if this is a leaf.- Specified by:
toStringTree
in interfaceTree
-
-