antlr-ng Tool Class Hierarchy / index / CommonTree
Class: CommonTree
A tree node that is wrapper for a Token object.
Extended by
Constructors
Constructor
new CommonTree(nodeOrToken?): CommonTree;
Parameters
nodeOrToken?
Token
| CommonTree
Returns
CommonTree
Properties
childIndex
childIndex: number = -1;
What index is this node in the child list? Range: 0..n-1
children
children: CommonTree[] = [];
parent
parent: null | CommonTree = null;
Who is the parent node of this node? If null, implies node is root.
startIndex
startIndex: number = -1;
What token indexes bracket all tokens associated with this node and below?
stopIndex
stopIndex: number = -1;
What token indexes bracket all tokens associated with this node and below?
token?
optional token: Token;
A single token is the payload.
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?
CommonTree
The child to add.
Returns
void
addChildren()
addChildren(kids): void;
Adds all elements of kids list as children of this node.
Parameters
kids
CommonTree
[]
The children to add.
Returns
void
deleteChild()
deleteChild(i): null | CommonTree;
Parameters
i
number
Returns
null
| CommonTree
dupNode()
dupNode(): CommonTree;
Returns
CommonTree
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
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.
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.
getCharPositionInLine()
getCharPositionInLine(): number;
Returns
number
getFirstChildWithType()
getFirstChildWithType(type): null | CommonTree;
Parameters
type
number
Returns
null
| CommonTree
getLine()
getLine(): number;
Returns
number
getSourceInterval()
getSourceInterval(): Interval;
Returns
Interval
getText()
getText(): string;
Returns
string
getTokenStartIndex()
getTokenStartIndex(): number;
Returns
number
getTokenStopIndex()
getTokenStopIndex(): number;
Returns
number
getType()
getType(): number;
Returns
number
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
CommonTree
The child to insert.
Returns
void
isNil()
isNil(): boolean;
Returns
boolean
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
CommonTree
The tree to replace the deleted children with.
Returns
void
sanityCheckParentAndChildIndexes()
Call Signature
sanityCheckParentAndChildIndexes(): void;
Returns
void
Call Signature
sanityCheckParentAndChildIndexes(parent, i): void;
Parameters
parent
undefined
| CommonTree
i
number
Returns
void
setChild()
setChild(i, t): void;
Parameters
i
number
t
CommonTree
Returns
void
setTokenStartIndex()
setTokenStartIndex(index): void;
Parameters
index
number
Returns
void
setTokenStopIndex()
setTokenStopIndex(index): void;
Parameters
index
number
Returns
void
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
toString()
toString(): string;
Returns
string
toStringTree()
toStringTree(): string;
Prints out a whole tree not just a node.
Returns
string
A string representation of the tree.