ParserRuleContext class
A rule invocation record for parsing.
Contains all of the information about the current rule not stored in the RuleContext. It handles parse tree children list, Any ATN state tracing, and the default values available for rule invocations: start, stop, rule index, current alt number.
Subclasses made for each rule and grammar track the parameters, return values, locals, and labels specific to that rule. These are the objects that are returned from rules.
Note text is not an actual field of a rule return value; it is computed from start and stop using the input stream's toString() method. I could add a ctor to this so that we can pass in and store the input stream, but I'm not sure we want to do that. It would seem to be undefined to get the .text property anyway if the rule matches tokens from multiple input streams.
I do not use getters for fields of objects that are used simply to group values such as this aggregate. The getters/setters are there to satisfy the superclass interface.
- Inheritance
-
- Object
- Tree
- SyntaxTree
- ParseTree
- RuleNode
- RuleContext
- ParserRuleContext
- Implementers
Constructors
- ParserRuleContext([RuleContext? parent, int? invokingStateNumber])
Properties
- altNumber ↔ int
-
For rule associated with this parse tree internal node, return
the outer alternative number used to match the input. Default
implementation does not compute nor store this alt num. Create
a subclass of ParserRuleContext with backing field and set
option contextSuperClass.
to set it.
getter/setter pairinherited
- childCount → int
-
no setteroverride
-
children
↔ List<
ParseTree> ? -
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.
getter/setter pair
-
exception
↔ RecognitionException<
IntStream> ? -
The exception that forced this rule to return. If the rule successfully
completed, this is null.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- invokingState ↔ int
-
What state invoked the rule associated with this context?
The "return address" is the followState of invokingState
If parent is null, this should be -1.
getter/setter pairinherited
- isEmpty → bool
-
A context is empty if there is no invoking state; meaning nobody call
current context.
no setterinherited
- parent ↔ ParserRuleContext?
-
Set the parent for this node.
covariantgetter/setter pairinherited-setteroverride-getter
- payload → RuleContext
-
no setterinherited
- ruleContext → RuleContext
-
no setterinherited
- ruleIndex → int
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sourceInterval → Interval
-
satisfy the ParseTree / SyntaxTree interface
no setteroverride
- start ↔ Token?
-
Get the initial/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 exceed stop.
getter/setter pair
- stop ↔ Token?
-
Get the initial/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 exceed stop.
getter/setter pair
- text → String
-
Return the combined text of all child nodes. This method only considers
tokens which have been added to the parse tree.
no setterinherited
Methods
-
accept<
T> (ParseTreeVisitor< T> visitor) → T? -
The ParseTreeVisitor needs a double dispatch method. */
inherited
-
addAnyChild<
T extends ParseTree> (T t) → T - 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.
-
addChild(
TerminalNode t) → TerminalNode - Add a token leaf node child and force its parent to be this node. */
-
addErrorNode(
ErrorNode errorNode) → ErrorNode - Add an error node child and force its parent to be this node.
-
copyFrom(
ParserRuleContext ctx) → void - 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).
-
depth(
) → int -
inherited
-
enterRule(
ParseTreeListener listener) → void -
exitRule(
ParseTreeListener listener) → void -
getChild<
T> (int i) → ParseTree? -
override
-
getRuleContext<
T extends ParserRuleContext> (int i) → T? -
getRuleContexts<
T extends ParserRuleContext> () → List< T> -
getToken(
int ttype, int i) → TerminalNode? -
getTokens(
int ttype) → List< TerminalNode> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeLastChild(
) → void - 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.
-
toInfoString(
Parser recognizer) → String - Used for rule context info debugging during parse-time, not so much for ATN debugging */
-
toString(
{List< String> ? ruleNames, Recognizer<ATNSimulator> ? recog, RuleContext? stop}) → String -
A string representation of this object.
inherited
-
toStringTree(
{List< String> ? ruleNames, Parser? parser}) → String -
Print out a whole tree, not just a node, in LISP format
(root child1 .. childN). Print just a node if this is a leaf.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- EMPTY → ParserRuleContext
-
final