public class ParserRuleContext extends RuleContext
| Modifier and Type | Field and Description |
|---|---|
List<ParseTree> |
children
If we are debugging or building a parse tree for a visitor,
we need to track all of the tokens and rule invocations associated
with this rule's context.
|
RecognitionException |
exception
The exception that forced this rule to return.
|
Token |
start
For debugging/tracing purposes, we want to track all of the nodes in
the ATN traversed by the parser for a particular rule.
|
Token |
stop
For debugging/tracing purposes, we want to track all of the nodes in
the ATN traversed by the parser for a particular rule.
|
invokingState, parent| Constructor and Description |
|---|
ParserRuleContext() |
ParserRuleContext(ParserRuleContext parent,
int invokingStateNumber) |
| Modifier and Type | Method and Description |
|---|---|
<T extends ParseTree> |
addAnyChild(T t)
Add a parse tree node to this as a child.
|
void |
addChild(RuleContext ruleInvocation) |
void |
addChild(TerminalNode t)
Add a token leaf node child.
|
TerminalNode |
addChild(Token matchedToken)
Deprecated.
|
ErrorNode |
addErrorNode(ErrorNode errorNode)
Add an error node child.
|
ErrorNode |
addErrorNode(Token badToken)
Deprecated.
|
void |
copyFrom(ParserRuleContext ctx)
COPY a ctx (I'm deliberately not using copy constructor) to avoid
confusion with creating node with parent.
|
static ParserRuleContext |
emptyContext() |
void |
enterRule(ParseTreeListener listener) |
void |
exitRule(ParseTreeListener listener) |
<T extends ParseTree> |
getChild(Class<? extends T> ctxType,
int i) |
ParseTree |
getChild(int i)
If there are children, get the
ith value indexed from 0. |
int |
getChildCount()
How many children are there? If there is none, then this
node represents a leaf node.
|
ParserRuleContext |
getParent()
The parent of this node.
|
<T extends ParserRuleContext> |
getRuleContext(Class<? extends T> ctxType,
int i) |
<T extends ParserRuleContext> |
getRuleContexts(Class<? extends T> ctxType) |
Interval |
getSourceInterval()
Return an
Interval indicating the index in the
TokenStream of the first and last token associated with this
subtree. |
Token |
getStart()
Get the initial token in this context.
|
Token |
getStop()
Get the final token in this context.
|
TerminalNode |
getToken(int ttype,
int i) |
List<? extends TerminalNode> |
getTokens(int ttype) |
void |
removeLastChild()
Used by enterOuterAlt to toss out a RuleContext previously added as
we entered a rule.
|
String |
toInfoString(Parser recognizer)
Used for rule context info debugging during parse-time, not so much for ATN debugging
|
accept, depth, getAltNumber, getChildContext, getPayload, getRuleContext, getRuleIndex, getText, isEmpty, setAltNumber, setParent, toString, toString, toString, toString, toString, toStringTree, toStringTree, toStringTreepublic List<ParseTree> children
public Token start
public Token stop
public RecognitionException exception
null.public ParserRuleContext()
public ParserRuleContext(@Nullable
ParserRuleContext parent,
int invokingStateNumber)
public static ParserRuleContext emptyContext()
public void copyFrom(ParserRuleContext ctx)
This is used in the generated parser code to flip a generic XContext node for rule X to a YContext for alt label Y. In that sense, it is not really a generic copy function.
If we do an error sync() at start of a rule, we might add error nodes to the generic XContext so this function must copy those nodes to the YContext as well else they are lost!
public void enterRule(ParseTreeListener listener)
public void exitRule(ParseTreeListener listener)
public <T extends ParseTree> T addAnyChild(T t)
public void addChild(RuleContext ruleInvocation)
public void addChild(TerminalNode t)
@Deprecated public TerminalNode addChild(Token matchedToken)
Parser.createTerminalNode(ParserRuleContext, Token). I'm leaving this
in for compatibility but the parser doesn't use this anymore.@Deprecated public ErrorNode addErrorNode(Token badToken)
Parser.createErrorNode(ParserRuleContext, Token). I'm leaving this
in for compatibility but the parser doesn't use this anymore.public void removeLastChild()
public ParserRuleContext getParent()
Treepublic ParseTree getChild(int i)
Treeith value indexed from 0.public TerminalNode getToken(int ttype, int i)
public List<? extends TerminalNode> getTokens(int ttype)
public <T extends ParserRuleContext> T getRuleContext(Class<? extends T> ctxType, int i)
public <T extends ParserRuleContext> List<? extends T> getRuleContexts(Class<? extends T> ctxType)
public int getChildCount()
TreegetChildCount in interface TreegetChildCount in class RuleContextpublic Interval getSourceInterval()
SyntaxTreeInterval 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 SyntaxTreegetSourceInterval in class RuleContextpublic Token getStart()
public Token getStop()
Copyright © 1992–2024 Daniel Sun. All rights reserved.