ParseContext class

Extends

ParserRuleContext

Constructors

ParseContext(ParserRuleContext | undefined, number)

Properties

ruleIndex

Inherited Properties

altNumber

Set the outer alternative number for this context node. Default implementation does nothing to avoid backing field overhead for trees that don't need it. Create a subclass of ParserRuleContext with backing field and set option contextSuperClass. @since 4.5.3

childCount
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.

exception

The exception that forced this rule to return. If the rule successfully completed, this is undefined.

invokingState
isEmpty

A context is empty if there is no invoking state; meaning nobody called current context.

parent
payload
ruleContext
sourceInterval
start

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.

stop

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.

text

Return the combined text of all child nodes. This method only considers tokens which have been added to the parse tree. 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.

Methods

accept<Result>(CommonRegexVisitor<Result>)
alternation()
enterRule(CommonRegexListener)
EOF()
exitRule(CommonRegexListener)

Inherited Methods

addAnyChild<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. 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(RuleContext)
addChild(TerminalNode)

Add a token leaf node child and force its parent to be this node.

addChild(Token)

Add a child to this node based upon matchedToken. It creates a TerminalNodeImpl rather than using [Token)](xref:Parser%23createTerminalNode(ParserRuleContext%2C). I'm leaving this in for compatibility but the parser doesn't use this anymore.

addErrorNode(ErrorNode)

Add an error node child and force its parent to be this node.

addErrorNode(Token)

Add a child to this node based upon badToken. It creates a ErrorNode rather than using [Token)](xref:Parser%23createErrorNode(ParserRuleContext%2C). I'm leaving this in for compatibility but the parser doesn't use this anymore.

copyFrom(ParserRuleContext)

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!

depth()
emptyContext()
getChild(number)
getChild<T>(number, { })
getChildContext(RuleContext, number)
getRuleContext<T>(number, { })
getRuleContexts<T>({ })
getToken(number, number)
getTokens(number)
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.

setParent(RuleContext)
toInfoString(Parser)

Used for rule context info debugging during parse-time, not so much for ATN debugging

toString()
toString(Recognizer<any, any> | undefined)
toString(Recognizer<any, any> | undefined, RuleContext | undefined)
toString(string[] | undefined)
toString(string[] | undefined, RuleContext | undefined)
toStringTree()
toStringTree(Parser)

Print out a whole tree, not just a node, in LISP format (root child1 .. childN). Print just a node if this is a leaf. We have to know the recognizer so we can get rule names.

toStringTree(string[] | undefined)

Print out a whole tree, not just a node, in LISP format (root child1 .. childN). Print just a node if this is a leaf.

tryGetChild<T>(number, { })
tryGetRuleContext<T>(number, { })
tryGetToken(number, number)

Constructor Details

ParseContext(ParserRuleContext | undefined, number)

new ParseContext(parent: ParserRuleContext | undefined, invokingState: number)

Parameters

parent

ParserRuleContext | undefined

invokingState

number

Property Details

ruleIndex

number ruleIndex

Property Value

number

Inherited Property Details

altNumber

Set the outer alternative number for this context node. Default implementation does nothing to avoid backing field overhead for trees that don't need it. Create a subclass of ParserRuleContext with backing field and set option contextSuperClass. @since 4.5.3

altNumber: number

Property Value

number

Inherited From RuleContext.altNumber

childCount

childCount: number

Property Value

number

Inherited From ParserRuleContext.childCount

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.

children?: ParseTree[]

Property Value

ParseTree[]

Inherited From ParserRuleContext.children

exception

The exception that forced this rule to return. If the rule successfully completed, this is undefined.

exception?: RecognitionException

Property Value

RecognitionException

Inherited From ParserRuleContext.exception

invokingState

invokingState: number

Property Value

number

Inherited From RuleContext.invokingState

isEmpty

A context is empty if there is no invoking state; meaning nobody called current context.

isEmpty: boolean

Property Value

boolean

Inherited From RuleContext.isEmpty

parent

parent: ParserRuleContext | undefined

Property Value

ParserRuleContext | undefined

Inherited From ParserRuleContext.parent

payload

payload: RuleContext

Property Value

RuleContext

Inherited From RuleContext.payload

ruleContext

ruleContext: this

Property Value

this

Inherited From ParserRuleContext.ruleContext

sourceInterval

sourceInterval: Interval

Property Value

Interval

Inherited From ParserRuleContext.sourceInterval

start

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.

start: Token

Property Value

Token

Inherited From ParserRuleContext.start

stop

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.

stop: Token | undefined

Property Value

Token | undefined

Inherited From ParserRuleContext.stop

text

Return the combined text of all child nodes. This method only considers tokens which have been added to the parse tree. 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.

text: string

Property Value

string

Inherited From RuleContext.text

Method Details

accept<Result>(CommonRegexVisitor<Result>)

function accept<Result>(visitor: CommonRegexVisitor<Result>): Result

Parameters

visitor

CommonRegexVisitor<Result>

Returns

Result

alternation()

function alternation(): AlternationContext

Returns

enterRule(CommonRegexListener)

function enterRule(listener: CommonRegexListener)

Parameters

EOF()

function EOF(): TerminalNode

Returns

TerminalNode

exitRule(CommonRegexListener)

function exitRule(listener: CommonRegexListener)

Parameters

Inherited Method Details

addAnyChild<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. 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

function addAnyChild<T>(t: T): T

Parameters

t

T

Returns

T

Inherited From ParserRuleContext.addAnyChild

addChild(RuleContext)

function addChild(ruleInvocation: RuleContext)

Parameters

ruleInvocation

RuleContext

Inherited From ParserRuleContext.addChild

addChild(TerminalNode)

Add a token leaf node child and force its parent to be this node.

function addChild(t: TerminalNode)

Parameters

t

TerminalNode

Inherited From ParserRuleContext.addChild

addChild(Token)

Warning

This API is now deprecated.

Use another overload instead.

Add a child to this node based upon matchedToken. It creates a TerminalNodeImpl rather than using [Token)](xref:Parser%23createTerminalNode(ParserRuleContext%2C). I'm leaving this in for compatibility but the parser doesn't use this anymore.

function addChild(matchedToken: Token): TerminalNode

Parameters

matchedToken

Token

Returns

TerminalNode

Inherited From ParserRuleContext.addChild

addErrorNode(ErrorNode)

Add an error node child and force its parent to be this node.

function addErrorNode(errorNode: ErrorNode): ErrorNode

Parameters

errorNode

ErrorNode

Returns

ErrorNode

Inherited From ParserRuleContext.addErrorNode

addErrorNode(Token)

Warning

This API is now deprecated.

Use another overload instead.

Add a child to this node based upon badToken. It creates a ErrorNode rather than using [Token)](xref:Parser%23createErrorNode(ParserRuleContext%2C). I'm leaving this in for compatibility but the parser doesn't use this anymore.

function addErrorNode(badToken: Token): ErrorNode

Parameters

badToken

Token

Returns

ErrorNode

Inherited From ParserRuleContext.addErrorNode

copyFrom(ParserRuleContext)

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!

function copyFrom(ctx: ParserRuleContext)

Parameters

ctx

ParserRuleContext

Inherited From ParserRuleContext.copyFrom

depth()

function depth(): number

Returns

number

Inherited From RuleContext.depth

emptyContext()

static function emptyContext(): ParserRuleContext

Returns

ParserRuleContext

Inherited From ParserRuleContext.emptyContext

getChild(number)

function getChild(i: number): ParseTree

Parameters

i

number

Returns

ParseTree

Inherited From ParserRuleContext.getChild

getChild<T>(number, { })

function getChild<T>(i: number, ctxType: {  }): T

Parameters

i

number

ctxType

{ }

Returns

T

Inherited From ParserRuleContext.getChild

getChildContext(RuleContext, number)

static function getChildContext(parent: RuleContext, invokingState: number): RuleContext

Parameters

parent

RuleContext

invokingState

number

Returns

RuleContext

Inherited From RuleContext.getChildContext

getRuleContext<T>(number, { })

function getRuleContext<T>(i: number, ctxType: {  }): T

Parameters

i

number

ctxType

{ }

Returns

T

Inherited From ParserRuleContext.getRuleContext

getRuleContexts<T>({ })

function getRuleContexts<T>(ctxType: {  }): T[]

Parameters

ctxType

{ }

Returns

T[]

Inherited From ParserRuleContext.getRuleContexts

getToken(number, number)

function getToken(ttype: number, i: number): TerminalNode

Parameters

ttype

number

i

number

Returns

TerminalNode

Inherited From ParserRuleContext.getToken

getTokens(number)

function getTokens(ttype: number): TerminalNode[]

Parameters

ttype

number

Returns

TerminalNode[]

Inherited From ParserRuleContext.getTokens

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.

function removeLastChild()

Inherited From ParserRuleContext.removeLastChild

setParent(RuleContext)

function setParent(parent: RuleContext)

Parameters

parent

RuleContext

Inherited From RuleContext.setParent

toInfoString(Parser)

Used for rule context info debugging during parse-time, not so much for ATN debugging

function toInfoString(recognizer: Parser): string

Parameters

recognizer

Parser

Returns

string

Inherited From ParserRuleContext.toInfoString

toString()

function toString(): string

Returns

string

Inherited From RuleContext.toString

toString(Recognizer<any, any> | undefined)

function toString(recog: Recognizer<any, any> | undefined): string

Parameters

recog

Recognizer<any, any> | undefined

Returns

string

Inherited From RuleContext.toString

toString(Recognizer<any, any> | undefined, RuleContext | undefined)

function toString(recog: Recognizer<any, any> | undefined, stop: RuleContext | undefined): string

Parameters

recog

Recognizer<any, any> | undefined

stop

RuleContext | undefined

Returns

string

Inherited From RuleContext.toString

toString(string[] | undefined)

function toString(ruleNames: string[] | undefined): string

Parameters

ruleNames

string[] | undefined

Returns

string

Inherited From RuleContext.toString

toString(string[] | undefined, RuleContext | undefined)

function toString(ruleNames: string[] | undefined, stop: RuleContext | undefined): string

Parameters

ruleNames

string[] | undefined

stop

RuleContext | undefined

Returns

string

Inherited From RuleContext.toString

toStringTree()

function toStringTree(): string

Returns

string

Inherited From RuleContext.toStringTree

toStringTree(Parser)

Print out a whole tree, not just a node, in LISP format (root child1 .. childN). Print just a node if this is a leaf. We have to know the recognizer so we can get rule names.

function toStringTree(recog: Parser): string

Parameters

recog

Parser

Returns

string

Inherited From RuleContext.toStringTree

toStringTree(string[] | undefined)

Print out a whole tree, not just a node, in LISP format (root child1 .. childN). Print just a node if this is a leaf.

function toStringTree(ruleNames: string[] | undefined): string

Parameters

ruleNames

string[] | undefined

Returns

string

Inherited From RuleContext.toStringTree

tryGetChild<T>(number, { })

function tryGetChild<T>(i: number, ctxType: {  }): T | undefined

Parameters

i

number

ctxType

{ }

Returns

T | undefined

Inherited From ParserRuleContext.tryGetChild

tryGetRuleContext<T>(number, { })

function tryGetRuleContext<T>(i: number, ctxType: {  }): T | undefined

Parameters

i

number

ctxType

{ }

Returns

T | undefined

Inherited From ParserRuleContext.tryGetRuleContext

tryGetToken(number, number)

function tryGetToken(ttype: number, i: number): TerminalNode | undefined

Parameters

ttype

number

i

number

Returns

TerminalNode | undefined

Inherited From ParserRuleContext.tryGetToken