Skip to content

antlr-ng Tool Class Hierarchy / index / GrammarRootAST

Class: GrammarRootAST ​

This is the root node for a grammar (for the top level grammarSpec rule).

Extends ​

  • GrammarASTWithOptions

Implements ​

  • IGrammarRootAST

Constructors ​

Constructor ​

ts
new GrammarRootAST(node): GrammarRootAST;

Parameters ​

node ​

GrammarRootAST

Returns ​

GrammarRootAST

Overrides ​

ts
GrammarASTWithOptions.constructor

Constructor ​

ts
new GrammarRootAST(t, tokenStream): GrammarRootAST;

Parameters ​

t ​

Token

tokenStream ​

TokenStream

Returns ​

GrammarRootAST

Overrides ​

ts
GrammarASTWithOptions.constructor

Constructor ​

ts
new GrammarRootAST(
   type, 
   t, 
   tokenStream): GrammarRootAST;

Parameters ​

type ​

number

t ​

Token

tokenStream ​

TokenStream

Returns ​

GrammarRootAST

Overrides ​

ts
GrammarASTWithOptions.constructor

Constructor ​

ts
new GrammarRootAST(
   type, 
   t, 
   text, 
   tokenStream): GrammarRootAST;

Parameters ​

type ​

number

t ​

Token

text ​

string

tokenStream ​

TokenStream

Returns ​

GrammarRootAST

Overrides ​

ts
GrammarASTWithOptions.constructor

Properties ​

astType ​

ts
readonly astType: string = "GrammarASTWithOptions";

A discriminator to distinguish between different grammar AST types without creating a circular dependency.

Implementation of ​

ts
IGrammarRootAST.astType

Inherited from ​

ts
GrammarASTWithOptions.astType

atnState? ​

ts
optional atnState: ATNState;

If we build an ATN, we make AST node point at left edge of ATN construct

Implementation of ​

ts
IGrammarRootAST.atnState

Inherited from ​

ts
GrammarASTWithOptions.atnState

childIndex ​

ts
childIndex: number = -1;

What index is this node in the child list? Range: 0..n-1

Implementation of ​

ts
IGrammarRootAST.childIndex

Inherited from ​

ts
GrammarASTWithOptions.childIndex

children ​

ts
children: CommonTree[] = [];

Implementation of ​

ts
IGrammarRootAST.children

Inherited from ​

ts
GrammarASTWithOptions.children

fileName ​

ts
fileName: string;

Implementation of ​

ts
IGrammarRootAST.fileName

g ​

ts
g: Grammar;

For process AST nodes from imported grammars.

Implementation of ​

ts
IGrammarRootAST.g

Inherited from ​

ts
GrammarASTWithOptions.g

grammarType ​

ts
grammarType: GrammarType;

Implementation of ​

ts
IGrammarRootAST.grammarType

hasErrors ​

ts
hasErrors: boolean = false;

Implementation of ​

ts
IGrammarRootAST.hasErrors

parent ​

ts
parent: null | CommonTree = null;

Who is the parent node of this node? If null, implies node is root.

Implementation of ​

ts
IGrammarRootAST.parent

Inherited from ​

ts
GrammarASTWithOptions.parent

startIndex ​

ts
startIndex: number = -1;

What token indexes bracket all tokens associated with this node and below?

Implementation of ​

ts
IGrammarRootAST.startIndex

Inherited from ​

ts
GrammarASTWithOptions.startIndex

stopIndex ​

ts
stopIndex: number = -1;

What token indexes bracket all tokens associated with this node and below?

Implementation of ​

ts
IGrammarRootAST.stopIndex

Inherited from ​

ts
GrammarASTWithOptions.stopIndex

textOverride ​

ts
textOverride: string;

Implementation of ​

ts
IGrammarRootAST.textOverride

Inherited from ​

ts
GrammarASTWithOptions.textOverride

token? ​

ts
optional token: Token;

A single token is the payload.

Implementation of ​

ts
IGrammarRootAST.token

Inherited from ​

ts
GrammarASTWithOptions.token

tokenStream ​

ts
readonly tokenStream: TokenStream;

Track stream used to create this tree

Implementation of ​

ts
IGrammarRootAST.tokenStream

toolConfiguration? ​

ts
optional toolConfiguration: IToolConfiguration;

Implementation of ​

ts
IGrammarRootAST.toolConfiguration

Methods ​

addChild() ​

ts
addChild(t?): void;

Adds t as child of this node.

Warning: if t has no children, but child does and child isNil then this routine moves children to t via t.children = child.children, i.e., without copying the array.

Parameters ​

t? ​

CommonTree

The child to add.

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.addChild

Inherited from ​

ts
GrammarASTWithOptions.addChild

addChildren() ​

ts
addChildren(kids): void;

Adds all elements of kids list as children of this node.

Parameters ​

kids ​

CommonTree[]

The children to add.

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.addChildren

Inherited from ​

ts
GrammarASTWithOptions.addChildren

deleteChild() ​

Call Signature ​

ts
deleteChild(i): null | CommonTree;
Parameters ​
i ​

number

Returns ​

null | CommonTree

Implementation of ​
ts
IGrammarRootAST.deleteChild
Inherited from ​
ts
GrammarASTWithOptions.deleteChild

Call Signature ​

ts
deleteChild(t): boolean;
Parameters ​
t ​

CommonTree

Returns ​

boolean

Implementation of ​
ts
IGrammarRootAST.deleteChild
Inherited from ​
ts
GrammarASTWithOptions.deleteChild

dupNode() ​

ts
dupNode(): GrammarRootAST;

Returns ​

GrammarRootAST

Implementation of ​

ts
IGrammarRootAST.dupNode

Overrides ​

ts
GrammarASTWithOptions.dupNode

freshenParentAndChildIndexes() ​

ts
freshenParentAndChildIndexes(offset?): void;

Sets the parent and child index values for all child of t.

Parameters ​

offset? ​

number

The index to start from.

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.freshenParentAndChildIndexes

Inherited from ​

ts
GrammarASTWithOptions.freshenParentAndChildIndexes

getAllChildrenWithType() ​

ts
getAllChildrenWithType(type): GrammarAST[];

Parameters ​

type ​

number

Returns ​

GrammarAST[]

Implementation of ​

ts
IGrammarRootAST.getAllChildrenWithType

Inherited from ​

ts
GrammarASTWithOptions.getAllChildrenWithType

getAltLabel() ​

ts
getAltLabel(): null | string;

Walk ancestors of this node until we find ALT with alt!=null or leftRecursiveAltInfo!=null. Then grab label if any. If not a rule element, just returns null.

Returns ​

null | string

Implementation of ​

ts
IGrammarRootAST.getAltLabel

Inherited from ​

ts
GrammarASTWithOptions.getAltLabel

getAncestor() ​

ts
getAncestor(ttype): null | CommonTree;

Walks upwards and get first ancestor with this token type.

Parameters ​

ttype ​

number

The token type to check for.

Returns ​

null | CommonTree

The first ancestor of this node with the specified token type, or null if no ancestor with the type exists.

Implementation of ​

ts
IGrammarRootAST.getAncestor

Inherited from ​

ts
GrammarASTWithOptions.getAncestor

getAncestors() ​

ts
protected getAncestors(): null | CommonTree[];

Returns ​

null | CommonTree[]

a list of all ancestors of this node. The first node of list is the root and the last is the parent of this node.

Implementation of ​

ts
IGrammarRootAST.getAncestors

Inherited from ​

ts
GrammarASTWithOptions.getAncestors

getCharPositionInLine() ​

ts
getCharPositionInLine(): number;

Returns ​

number

Implementation of ​

ts
IGrammarRootAST.getCharPositionInLine

Inherited from ​

ts
GrammarASTWithOptions.getCharPositionInLine

getFirstChildWithType() ​

ts
getFirstChildWithType(type): null | CommonTree;

Parameters ​

type ​

number

Returns ​

null | CommonTree

Implementation of ​

ts
IGrammarRootAST.getFirstChildWithType

Inherited from ​

ts
GrammarASTWithOptions.getFirstChildWithType

getFirstDescendantWithType() ​

ts
getFirstDescendantWithType(typeOrTypes): null | CommonTree;

Parameters ​

typeOrTypes ​

number | BitSet

Returns ​

null | CommonTree

Implementation of ​

ts
IGrammarRootAST.getFirstDescendantWithType

Inherited from ​

ts
GrammarASTWithOptions.getFirstDescendantWithType

getGrammarName() ​

ts
getGrammarName(): null | string;

Returns ​

null | string

Implementation of ​

ts
IGrammarRootAST.getGrammarName

getLine() ​

ts
getLine(): number;

Returns ​

number

Implementation of ​

ts
IGrammarRootAST.getLine

Inherited from ​

ts
GrammarASTWithOptions.getLine

getNodesWithType() ​

ts
getNodesWithType(typeOrTypes): GrammarAST[];

Parameters ​

typeOrTypes ​

null | number | IntervalSet

Returns ​

GrammarAST[]

Implementation of ​

ts
IGrammarRootAST.getNodesWithType

Inherited from ​

ts
GrammarASTWithOptions.getNodesWithType

getNodesWithTypePreorderDFS() ​

ts
getNodesWithTypePreorderDFS(types): GrammarAST[];

Parameters ​

types ​

IntervalSet

Returns ​

GrammarAST[]

Implementation of ​

ts
IGrammarRootAST.getNodesWithTypePreorderDFS

Inherited from ​

ts
GrammarASTWithOptions.getNodesWithTypePreorderDFS

getNodeWithTokenIndex() ​

ts
getNodeWithTokenIndex(index): null | GrammarAST;

Parameters ​

index ​

number

Returns ​

null | GrammarAST

Implementation of ​

ts
IGrammarRootAST.getNodeWithTokenIndex

Inherited from ​

ts
GrammarASTWithOptions.getNodeWithTokenIndex

getNumberOfOptions() ​

ts
getNumberOfOptions(): number;

Returns ​

number

Implementation of ​

ts
IGrammarRootAST.getNumberOfOptions

Inherited from ​

ts
GrammarASTWithOptions.getNumberOfOptions

getOptionAST() ​

ts
getOptionAST(key): undefined | GrammarAST;

Gets AST node holding value for option key; ignores default options and command-line forced options.

Parameters ​

key ​

string

Returns ​

undefined | GrammarAST

Implementation of ​

ts
IGrammarRootAST.getOptionAST

Inherited from ​

ts
GrammarASTWithOptions.getOptionAST

getOptions() ​

ts
getOptions(): Map<string, null | GrammarAST>;

Returns ​

Map<string, null | GrammarAST>

Implementation of ​

ts
IGrammarRootAST.getOptions

Inherited from ​

ts
GrammarASTWithOptions.getOptions

getOptionString() ​

ts
getOptionString(key): undefined | string;

Parameters ​

key ​

string

Returns ​

undefined | string

Implementation of ​

ts
IGrammarRootAST.getOptionString

Overrides ​

ts
GrammarASTWithOptions.getOptionString

getSourceInterval() ​

ts
getSourceInterval(): Interval;

Returns ​

Interval

Implementation of ​

ts
IGrammarRootAST.getSourceInterval

Inherited from ​

ts
GrammarASTWithOptions.getSourceInterval

getText() ​

ts
getText(): string;

Returns ​

string

Implementation of ​

ts
IGrammarRootAST.getText

Inherited from ​

ts
GrammarASTWithOptions.getText

getTokenStartIndex() ​

ts
getTokenStartIndex(): number;

Returns ​

number

Implementation of ​

ts
IGrammarRootAST.getTokenStartIndex

Inherited from ​

ts
GrammarASTWithOptions.getTokenStartIndex

getTokenStopIndex() ​

ts
getTokenStopIndex(): number;

Returns ​

number

Implementation of ​

ts
IGrammarRootAST.getTokenStopIndex

Inherited from ​

ts
GrammarASTWithOptions.getTokenStopIndex

getType() ​

ts
getType(): number;

Returns ​

number

Implementation of ​

ts
IGrammarRootAST.getType

Inherited from ​

ts
GrammarASTWithOptions.getType

insertChild() ​

ts
insertChild(i, t): void;

Inserts child t at child position i (0..n - 1) by shifting children i + 1..n - 1 to the right one position. Sets parent/indexes properly but does NOT collapse nil-rooted t's that come in here like addChild.

Parameters ​

i ​

number

The index to insert the child at.

t ​

CommonTree

The child to insert.

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.insertChild

Inherited from ​

ts
GrammarASTWithOptions.insertChild

isNil() ​

ts
isNil(): boolean;

Returns ​

boolean

Implementation of ​

ts
IGrammarRootAST.isNil

Inherited from ​

ts
GrammarASTWithOptions.isNil

replaceChildren() ​

ts
replaceChildren(
   startChildIndex, 
   stopChildIndex, 
   t): void;

Deletes children from start to stop and replaces with t even if t is a list (nil-root tree). Number of children can increase or decrease. For huge child lists, inserting children can force walking rest of children to set their child index - could be slow.

Parameters ​

startChildIndex ​

number

The index to start deleting children.

stopChildIndex ​

number

The index to stop deleting children.

t ​

CommonTree

The tree to replace the deleted children with.

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.replaceChildren

Inherited from ​

ts
GrammarASTWithOptions.replaceChildren

sanityCheckParentAndChildIndexes() ​

Call Signature ​

ts
sanityCheckParentAndChildIndexes(): void;
Returns ​

void

Implementation of ​
ts
IGrammarRootAST.sanityCheckParentAndChildIndexes
Inherited from ​
ts
GrammarASTWithOptions.sanityCheckParentAndChildIndexes

Call Signature ​

ts
sanityCheckParentAndChildIndexes(parent, i): void;
Parameters ​
parent ​

undefined | CommonTree

i ​

number

Returns ​

void

Implementation of ​
ts
IGrammarRootAST.sanityCheckParentAndChildIndexes
Inherited from ​
ts
GrammarASTWithOptions.sanityCheckParentAndChildIndexes

setChild() ​

ts
setChild(i, t): void;

Parameters ​

i ​

number

t ​

CommonTree

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setChild

Inherited from ​

ts
GrammarASTWithOptions.setChild

setOption() ​

ts
setOption(key, node): void;

Parameters ​

key ​

string

node ​

null | GrammarAST

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setOption

Inherited from ​

ts
GrammarASTWithOptions.setOption

setText() ​

ts
setText(text): void;

Parameters ​

text ​

string

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setText

Inherited from ​

ts
GrammarASTWithOptions.setText

setTokenStartIndex() ​

ts
setTokenStartIndex(index): void;

Parameters ​

index ​

number

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setTokenStartIndex

Inherited from ​

ts
GrammarASTWithOptions.setTokenStartIndex

setTokenStopIndex() ​

ts
setTokenStopIndex(index): void;

Parameters ​

index ​

number

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setTokenStopIndex

Inherited from ​

ts
GrammarASTWithOptions.setTokenStopIndex

setType() ​

ts
setType(type): void;

Parameters ​

type ​

number

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setType

Inherited from ​

ts
GrammarASTWithOptions.setType

setUnknownTokenBoundaries() ​

ts
setUnknownTokenBoundaries(): void;

For every node in this subtree, make sure it's start/stop token's are set. Walks depth first, visits bottom up. Only updates nodes with at least one token index < 0.

Returns ​

void

Implementation of ​

ts
IGrammarRootAST.setUnknownTokenBoundaries

Inherited from ​

ts
GrammarASTWithOptions.setUnknownTokenBoundaries

toString() ​

ts
toString(): string;

Returns ​

string

Implementation of ​

ts
IGrammarRootAST.toString

Inherited from ​

ts
GrammarASTWithOptions.toString

toStringTree() ​

ts
toStringTree(): string;

Prints out a whole tree not just a node.

Returns ​

string

A string representation of the tree.

Implementation of ​

ts
IGrammarRootAST.toStringTree

Inherited from ​

ts
GrammarASTWithOptions.toStringTree

visit() ​

ts
visit<T>(v): T;

Type Parameters ​

T ​

T

Parameters ​

v ​

IGrammarASTVisitor<T>

Returns ​

T

Implementation of ​

ts
IGrammarRootAST.visit

Overrides ​

ts
GrammarASTWithOptions.visit