public class RuleContext extends Object implements RuleNode
ParserRuleContext
Modifier and Type | Field and Description |
---|---|
static ParserRuleContext |
EMPTY |
int |
invokingState
What state invoked the rule associated with this context?
|
RuleContext |
parent
What context invoked this rule?
|
Constructor and Description |
---|
RuleContext() |
RuleContext(RuleContext parent,
int invokingState) |
Modifier and Type | Method and Description |
---|---|
<T> T |
accept(ParseTreeVisitor<? extends T> visitor)
The
ParseTreeVisitor needs a double dispatch method. |
int |
depth() |
int |
getAltNumber()
For rule associated with this parse tree internal node, return
the outer alternative number used to match the input.
|
ParseTree |
getChild(int i)
If there are children, get the
i th value indexed from 0. |
int |
getChildCount()
How many children are there?
|
RuleContext |
getParent()
The parent of this node.
|
RuleContext |
getPayload()
This method returns whatever object represents the data at this node.
|
RuleContext |
getRuleContext() |
int |
getRuleIndex() |
Interval |
getSourceInterval()
Return an
Interval indicating the index in the
TokenStream of the first and last token associated with this
subtree. |
String |
getText()
Return the combined text of all child nodes.
|
boolean |
isEmpty()
A context is empty if there is no invoking state; meaning nobody called
current context.
|
void |
setAltNumber(int altNumber)
Set the outer alternative number for this context node.
|
void |
setParent(RuleContext parent)
Set the parent for this node.
|
String |
toString() |
String |
toString(List<String> ruleNames) |
String |
toString(List<String> ruleNames,
RuleContext stop) |
String |
toString(Recognizer<?,?> recog) |
String |
toString(Recognizer<?,?> recog,
RuleContext stop) |
String |
toStringTree()
Print out a whole tree, not just a node, in LISP format
(root child1 .. childN) . |
String |
toStringTree(List<String> ruleNames)
Print out a whole tree, not just a node, in LISP format
(root child1 .. childN).
|
String |
toStringTree(Parser recog)
Print out a whole tree, not just a node, in LISP format
(root child1 .. childN).
|
public static final ParserRuleContext EMPTY
public RuleContext parent
public int invokingState
public RuleContext()
public RuleContext(RuleContext parent, int invokingState)
public int depth()
public boolean isEmpty()
public Interval getSourceInterval()
SyntaxTree
Interval
indicating the index in the
TokenStream
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.
getSourceInterval
in interface SyntaxTree
public RuleContext getRuleContext()
getRuleContext
in interface RuleNode
public RuleContext getParent()
Tree
public RuleContext getPayload()
Tree
Token
representing
a leaf node or a RuleContext
object representing a rule
invocation. For abstract syntax trees (ASTs), this is a Token
object.getPayload
in interface Tree
public String getText()
Since tokens on hidden channels (e.g. whitespace or comments) are not added to the parse trees, they will not appear in the output of this method.
public int getRuleIndex()
public int getAltNumber()
public void setAltNumber(int altNumber)
public void setParent(RuleContext parent)
ParseTree
setParent
in interface ParseTree
ParseTree.setParent(org.antlr.v4.runtime.RuleContext)
commentpublic ParseTree getChild(int i)
Tree
i
th value indexed from 0.public int getChildCount()
Tree
getChildCount
in interface Tree
public <T> T accept(ParseTreeVisitor<? extends T> visitor)
ParseTree
ParseTreeVisitor
needs a double dispatch method.public String toStringTree(Parser recog)
toStringTree
in interface ParseTree
public String toStringTree(List<String> ruleNames)
public String toStringTree()
Tree
(root child1 .. childN)
. Print just a node if this is a leaf.toStringTree
in interface Tree
public final String toString(Recognizer<?,?> recog)
public String toString(Recognizer<?,?> recog, RuleContext stop)
public String toString(List<String> ruleNames, RuleContext stop)
Copyright © 1992–2021 ANTLR. All rights reserved.