antlr-ng Tool Class Hierarchy / index / GrammarAST
Class: GrammarAST
A tree node that is wrapper for a Token object.
Extends
Implements
IGrammarAST
Constructors
Constructor
new GrammarAST(nodeOrToken?): GrammarAST;
Parameters
nodeOrToken?
Token
| GrammarAST
Returns
GrammarAST
Overrides
Constructor
new GrammarAST(
type,
t?,
text?): GrammarAST;
Parameters
type
number
t?
Token
text?
string
Returns
GrammarAST
Overrides
CommonTree.constructor
Properties
astType
readonly astType: string = "GrammarAST";
A discriminator to distinguish between different grammar AST types without creating a circular dependency.
Implementation of
IGrammarAST.astType
atnState?
optional atnState: ATNState;
If we build an ATN, we make AST node point at left edge of ATN construct
Implementation of
IGrammarAST.atnState
childIndex
childIndex: number = -1;
What index is this node in the child list? Range: 0..n-1
Implementation of
IGrammarAST.childIndex
Inherited from
children
children: CommonTree[] = [];
Implementation of
IGrammarAST.children
Inherited from
g
g: Grammar;
For process AST nodes from imported grammars.
Implementation of
IGrammarAST.g
parent
parent: null | CommonTree = null;
Who is the parent node of this node? If null, implies node is root.
Implementation of
IGrammarAST.parent
Inherited from
startIndex
startIndex: number = -1;
What token indexes bracket all tokens associated with this node and below?
Implementation of
IGrammarAST.startIndex
Inherited from
stopIndex
stopIndex: number = -1;
What token indexes bracket all tokens associated with this node and below?
Implementation of
IGrammarAST.stopIndex
Inherited from
textOverride
textOverride: string;
Implementation of
IGrammarAST.textOverride
token?
optional token: Token;
A single token is the payload.
Implementation of
IGrammarAST.token
Inherited from
Methods
addChild()
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?
The child to add.
Returns
void
Implementation of
IGrammarAST.addChild
Inherited from
addChildren()
addChildren(kids): void;
Adds all elements of kids list as children of this node.
Parameters
kids
The children to add.
Returns
void
Implementation of
IGrammarAST.addChildren
Inherited from
deleteChild()
Call Signature
deleteChild(i): null | CommonTree;
Parameters
i
number
Returns
null
| CommonTree
Implementation of
IGrammarAST.deleteChild
Overrides
Call Signature
deleteChild(t): boolean;
Parameters
t
Returns
boolean
Implementation of
IGrammarAST.deleteChild
Overrides
CommonTree.deleteChild
dupNode()
dupNode(): GrammarAST;
Returns
GrammarAST
Implementation of
IGrammarAST.dupNode
Overrides
freshenParentAndChildIndexes()
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
IGrammarAST.freshenParentAndChildIndexes
Inherited from
CommonTree
.freshenParentAndChildIndexes
getAllChildrenWithType()
getAllChildrenWithType(type): GrammarAST[];
Parameters
type
number
Returns
GrammarAST
[]
Implementation of
IGrammarAST.getAllChildrenWithType
getAltLabel()
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
IGrammarAST.getAltLabel
getAncestor()
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
IGrammarAST.getAncestor
Inherited from
getAncestors()
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
IGrammarAST.getAncestors
Inherited from
getCharPositionInLine()
getCharPositionInLine(): number;
Returns
number
Implementation of
IGrammarAST.getCharPositionInLine
Inherited from
CommonTree
.getCharPositionInLine
getFirstChildWithType()
getFirstChildWithType(type): null | CommonTree;
Parameters
type
number
Returns
null
| CommonTree
Implementation of
IGrammarAST.getFirstChildWithType
Inherited from
CommonTree
.getFirstChildWithType
getFirstDescendantWithType()
getFirstDescendantWithType(typeOrTypes): null | CommonTree;
Parameters
typeOrTypes
number
| BitSet
Returns
null
| CommonTree
Implementation of
IGrammarAST.getFirstDescendantWithType
getLine()
getLine(): number;
Returns
number
Implementation of
IGrammarAST.getLine
Inherited from
getNodesWithType()
getNodesWithType(typeOrTypes): GrammarAST[];
Parameters
typeOrTypes
null
| number
| IntervalSet
Returns
GrammarAST
[]
Implementation of
IGrammarAST.getNodesWithType
getNodesWithTypePreorderDFS()
getNodesWithTypePreorderDFS(types): GrammarAST[];
Parameters
types
IntervalSet
Returns
GrammarAST
[]
Implementation of
IGrammarAST.getNodesWithTypePreorderDFS
getNodeWithTokenIndex()
getNodeWithTokenIndex(index): null | GrammarAST;
Parameters
index
number
Returns
null
| GrammarAST
Implementation of
IGrammarAST.getNodeWithTokenIndex
getSourceInterval()
getSourceInterval(): Interval;
Returns
Interval
Implementation of
IGrammarAST.getSourceInterval
Inherited from
getText()
getText(): string;
Returns
string
Implementation of
IGrammarAST.getText
Inherited from
getTokenStartIndex()
getTokenStartIndex(): number;
Returns
number
Implementation of
IGrammarAST.getTokenStartIndex
Inherited from
getTokenStopIndex()
getTokenStopIndex(): number;
Returns
number
Implementation of
IGrammarAST.getTokenStopIndex
Inherited from
getType()
getType(): number;
Returns
number
Implementation of
IGrammarAST.getType
Inherited from
insertChild()
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
The child to insert.
Returns
void
Implementation of
IGrammarAST.insertChild
Inherited from
isNil()
isNil(): boolean;
Returns
boolean
Implementation of
IGrammarAST.isNil
Inherited from
replaceChildren()
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
The tree to replace the deleted children with.
Returns
void
Implementation of
IGrammarAST.replaceChildren
Inherited from
sanityCheckParentAndChildIndexes()
Call Signature
sanityCheckParentAndChildIndexes(): void;
Returns
void
Implementation of
IGrammarAST.sanityCheckParentAndChildIndexes
Inherited from
CommonTree
.sanityCheckParentAndChildIndexes
Call Signature
sanityCheckParentAndChildIndexes(parent, i): void;
Parameters
parent
undefined
| CommonTree
i
number
Returns
void
Implementation of
IGrammarAST.sanityCheckParentAndChildIndexes
Inherited from
CommonTree
.sanityCheckParentAndChildIndexes
setChild()
setChild(i, t): void;
Parameters
i
number
t
Returns
void
Implementation of
IGrammarAST.setChild
Inherited from
setText()
setText(text): void;
Parameters
text
string
Returns
void
Implementation of
IGrammarAST.setText
setTokenStartIndex()
setTokenStartIndex(index): void;
Parameters
index
number
Returns
void
Implementation of
IGrammarAST.setTokenStartIndex
Inherited from
setTokenStopIndex()
setTokenStopIndex(index): void;
Parameters
index
number
Returns
void
Implementation of
IGrammarAST.setTokenStopIndex
Inherited from
setType()
setType(type): void;
Parameters
type
number
Returns
void
Implementation of
IGrammarAST.setType
setUnknownTokenBoundaries()
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
IGrammarAST.setUnknownTokenBoundaries
Inherited from
CommonTree
.setUnknownTokenBoundaries
toString()
toString(): string;
Returns
string
Implementation of
IGrammarAST.toString
Inherited from
toStringTree()
toStringTree(): string;
Prints out a whole tree not just a node.
Returns
string
A string representation of the tree.
Implementation of
IGrammarAST.toStringTree
Inherited from
visit()
visit<T>(v): T;
Type Parameters
T
T
Parameters
v
IGrammarASTVisitor
<T
>
Returns
T
Implementation of
IGrammarAST.visit