Class ParserRuleContext
- All Implemented Interfaces:
ParseTree,RuleNode,SyntaxTree,Tree
- Direct Known Subclasses:
graphemesParser.Emoji_sequenceContext,graphemesParser.Grapheme_clusterContext,graphemesParser.GraphemesContext,GroovyLikeParser.ArgsContext,GroovyLikeParser.BlockContext,GroovyLikeParser.ClassBodyContext,GroovyLikeParser.ClosureContext,GroovyLikeParser.CompilationUnitContext,GroovyLikeParser.ExpressionContext,GroovyLikeParser.FieldDeclContext,GroovyLikeParser.MemberContext,GroovyLikeParser.MethodDeclContext,GroovyLikeParser.NlsContext,GroovyLikeParser.PackageDeclContext,GroovyLikeParser.ParamsContext,GroovyLikeParser.PostfixContext,GroovyLikeParser.PrimaryContext,GroovyLikeParser.QualifiedNameContext,GroovyLikeParser.SepContext,GroovyLikeParser.StatementContext,GroovyLikeParser.TypeDeclContext,InterpreterRuleContext,JavaParser.AnnotationConstantRestContext,JavaParser.AnnotationContext,JavaParser.AnnotationMethodOrConstantRestContext,JavaParser.AnnotationMethodRestContext,JavaParser.AnnotationNameContext,JavaParser.AnnotationTypeBodyContext,JavaParser.AnnotationTypeDeclarationContext,JavaParser.AnnotationTypeElementDeclarationContext,JavaParser.AnnotationTypeElementRestContext,JavaParser.ArgumentsContext,JavaParser.ArrayCreatorRestContext,JavaParser.ArrayInitializerContext,JavaParser.BlockContext,JavaParser.BlockStatementContext,JavaParser.CatchClauseContext,JavaParser.CatchTypeContext,JavaParser.ClassBodyContext,JavaParser.ClassBodyDeclarationContext,JavaParser.ClassCreatorRestContext,JavaParser.ClassDeclarationContext,JavaParser.ClassOrInterfaceModifierContext,JavaParser.ClassOrInterfaceTypeContext,JavaParser.CompilationUnitContext,JavaParser.ConstantDeclaratorContext,JavaParser.ConstantExpressionContext,JavaParser.ConstDeclarationContext,JavaParser.ConstructorBodyContext,JavaParser.ConstructorDeclarationContext,JavaParser.CreatedNameContext,JavaParser.CreatorContext,JavaParser.DefaultValueContext,JavaParser.ElementValueArrayInitializerContext,JavaParser.ElementValueContext,JavaParser.ElementValuePairContext,JavaParser.ElementValuePairsContext,JavaParser.EnhancedForControlContext,JavaParser.EnumBodyDeclarationsContext,JavaParser.EnumConstantContext,JavaParser.EnumConstantNameContext,JavaParser.EnumConstantsContext,JavaParser.EnumDeclarationContext,JavaParser.ExplicitGenericInvocationContext,JavaParser.ExplicitGenericInvocationSuffixContext,JavaParser.ExpressionContext,JavaParser.ExpressionListContext,JavaParser.FieldDeclarationContext,JavaParser.FinallyBlockContext,JavaParser.ForControlContext,JavaParser.ForInitContext,JavaParser.FormalParameterContext,JavaParser.FormalParameterListContext,JavaParser.FormalParametersContext,JavaParser.ForUpdateContext,JavaParser.GenericConstructorDeclarationContext,JavaParser.GenericInterfaceMethodDeclarationContext,JavaParser.GenericMethodDeclarationContext,JavaParser.ImportDeclarationContext,JavaParser.InnerCreatorContext,JavaParser.InterfaceBodyContext,JavaParser.InterfaceBodyDeclarationContext,JavaParser.InterfaceDeclarationContext,JavaParser.InterfaceMemberDeclarationContext,JavaParser.InterfaceMethodDeclarationContext,JavaParser.LastFormalParameterContext,JavaParser.LiteralContext,JavaParser.LocalVariableDeclarationContext,JavaParser.LocalVariableDeclarationStatementContext,JavaParser.MemberDeclarationContext,JavaParser.MethodBodyContext,JavaParser.MethodDeclarationContext,JavaParser.ModifierContext,JavaParser.NonWildcardTypeArgumentsContext,JavaParser.NonWildcardTypeArgumentsOrDiamondContext,JavaParser.PackageDeclarationContext,JavaParser.ParExpressionContext,JavaParser.PrimaryContext,JavaParser.PrimitiveTypeContext,JavaParser.QualifiedNameContext,JavaParser.QualifiedNameListContext,JavaParser.ResourceContext,JavaParser.ResourcesContext,JavaParser.ResourceSpecificationContext,JavaParser.StatementContext,JavaParser.StatementExpressionContext,JavaParser.SuperSuffixContext,JavaParser.SwitchBlockStatementGroupContext,JavaParser.SwitchLabelContext,JavaParser.TypeArgumentContext,JavaParser.TypeArgumentsContext,JavaParser.TypeArgumentsOrDiamondContext,JavaParser.TypeBoundContext,JavaParser.TypeContext,JavaParser.TypeDeclarationContext,JavaParser.TypeListContext,JavaParser.TypeParameterContext,JavaParser.TypeParametersContext,JavaParser.VariableDeclaratorContext,JavaParser.VariableDeclaratorIdContext,JavaParser.VariableDeclaratorsContext,JavaParser.VariableInitializerContext,JavaParser.VariableModifierContext,RuleContextWithAltNum
-
Field Summary
FieldsModifier and TypeFieldDescriptionIf 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.private static final intInitialchildrencapacity.private static final ParserRuleContextThe exception that forced this rule to return.For debugging/tracing purposes, we want to track all of the nodes in the ATN traversed by the parser for a particular rule.For debugging/tracing purposes, we want to track all of the nodes in the ATN traversed by the parser for a particular rule.Fields inherited from class org.antlr.v4.runtime.RuleContext
invokingState, parent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends ParseTree>
TaddAnyChild(T t) Add a parse tree node to this as a child.voidaddChild(RuleContext ruleInvocation) Deprecated.voidAdd a token leaf node child.addErrorNode(Token badToken) Deprecated.addErrorNode(ErrorNode errorNode) Add an error node child.voidCOPY a ctx (I'm deliberately not using copy constructor) to avoid confusion with creating node with parent.static ParserRuleContextvoidenterRule(ParseTreeListener listener) voidexitRule(ParseTreeListener listener) getChild(int i) If there are children, get theith value indexed from 0.<T extends ParseTree>
TintHow many children are there? If there is none, then this node represents a leaf node.The parent of this node.<T extends ParserRuleContext>
TgetRuleContext(Class<? extends T> ctxType, int i) <T extends ParserRuleContext>
List<? extends T>getRuleContexts(Class<? extends T> ctxType) Return anIntervalindicating the index in theTokenStreamof the first and last token associated with this subtree.getStart()Get the initial token in this context.getStop()Get the final token in this context.getToken(int ttype, int i) List<? extends TerminalNode>getTokens(int ttype) voidUsed by enterOuterAlt to toss out a RuleContext previously added as we entered a rule.toInfoString(Parser recognizer) Used for rule context info debugging during parse-time, not so much for ATN debuggingMethods inherited from class org.antlr.v4.runtime.RuleContext
accept, depth, getAltNumber, getChildContext, getPayload, getRuleContext, getRuleIndex, getText, isEmpty, setAltNumber, setParent, toString, toString, toString, toString, toString, toStringTree, toStringTree, toStringTree
-
Field Details
-
EMPTY
-
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. This is empty for parsing w/o tree constr. operation because we don't the need to track the details about how we parse this rule. -
start
For debugging/tracing purposes, we want to track all of the nodes in the ATN traversed by the parser for a particular rule. This list indicates the sequence of ATN nodes used to match the elements of the children list. This list does not include ATN nodes and other rules used to match rule invocations. It traces the rule invocation node itself but nothing inside that other rule's ATN submachine. There is NOT a one-to-one correspondence between the children and states list. There are typically many nodes in the ATN traversed for each element in the children list. For example, for a rule invocation there is the invoking state and the following state. The parser setState() method updates field s and adds it to this list if we are debugging/tracing. This does not trace states visited during prediction. -
stop
For debugging/tracing purposes, we want to track all of the nodes in the ATN traversed by the parser for a particular rule. This list indicates the sequence of ATN nodes used to match the elements of the children list. This list does not include ATN nodes and other rules used to match rule invocations. It traces the rule invocation node itself but nothing inside that other rule's ATN submachine. There is NOT a one-to-one correspondence between the children and states list. There are typically many nodes in the ATN traversed for each element in the children list. For example, for a rule invocation there is the invoking state and the following state. The parser setState() method updates field s and adds it to this list if we are debugging/tracing. This does not trace states visited during prediction. -
exception
The exception that forced this rule to return. If the rule successfully completed, this isnull. -
CHILDREN_INITIAL_CAPACITY
private static final int CHILDREN_INITIAL_CAPACITYInitialchildrencapacity. Most rule contexts hold a handful of children; the JDK default of 10 wastes the unused tail on every internal node when parse trees are built.- See Also:
-
-
Constructor Details
-
ParserRuleContext
public ParserRuleContext() -
ParserRuleContext
-
-
Method Details
-
emptyContext
-
copyFrom
COPY a ctx (I'm deliberately not using copy constructor) to avoid confusion with creating node with parent. Does not copy children (except error leaves).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!
-
enterRule
-
exitRule
-
addAnyChild
Add a parse tree node to this as a child. Works for internal and leaf nodes. Does not set parent link; other add methods must do that. Other addChild methods call this. We cannot set the parent pointer of the incoming node because the existing interfaces do not have a setParent() method and I don't want to break backward compatibility for this.- Since:
- 4.7
-
addChild
-
addChild
Add a token leaf node child. -
addErrorNode
Add an error node child.- Since:
- 4.7
-
addChild
Deprecated.Add a child to this node based upon matchedToken. It creates a TerminalNodeImpl rather than usingParser.createTerminalNode(ParserRuleContext, Token). I'm leaving this in for compatibility but the parser doesn't use this anymore. -
addErrorNode
Deprecated.Add a child to this node based upon badToken. It creates a ErrorNodeImpl rather than usingParser.createErrorNode(ParserRuleContext, Token). I'm leaving this in for compatibility but the parser doesn't use this anymore. -
removeLastChild
public void removeLastChild()Used by enterOuterAlt to toss out a RuleContext previously added as we entered a rule. If we have # label, we will need to remove generic ruleContext object. -
getParent
Description copied from interface:TreeThe parent of this node. If the return value is null, then this node is the root of the tree. -
getChild
Description copied from interface:TreeIf there are children, get theith value indexed from 0. -
getChild
-
getToken
-
getTokens
-
getRuleContext
-
getRuleContexts
-
getChildCount
public int getChildCount()Description copied from interface:TreeHow many children are there? If there is none, then this node represents a leaf node.- Specified by:
getChildCountin interfaceTree- Overrides:
getChildCountin classRuleContext
-
getSourceInterval
Description copied from interface:SyntaxTreeReturn anIntervalindicating the index in theTokenStreamof 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:
getSourceIntervalin interfaceSyntaxTree- Overrides:
getSourceIntervalin classRuleContext
-
getStart
Get the initial token in this context. Note that the range from start to stop is inclusive, so for rules that do not consume anything (for example, zero length or error productions) this token may exceed stop. -
getStop
Get the final token in this context. Note that the range from start to stop is inclusive, so for rules that do not consume anything (for example, zero length or error productions) this token may precede start. -
toInfoString
Used for rule context info debugging during parse-time, not so much for ATN debugging
-