UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

98 lines (97 loc) 3.93 kB
import { Interval, Token } from "antlr4ng"; /** A tree node that is wrapper for a Token object. */ export declare class CommonTree { /** A single token is the payload. */ token?: Token; /** Who is the parent node of this node? If null, implies node is root. */ parent: CommonTree | null; /** What token indexes bracket all tokens associated with this node and below? */ startIndex: number; /** What token indexes bracket all tokens associated with this node and below? */ stopIndex: number; /** What index is this node in the child list? Range: 0..n-1 */ childIndex: number; children: CommonTree[]; constructor(nodeOrToken?: CommonTree | Token); getFirstChildWithType(type: number): CommonTree | null; dupNode(): CommonTree; /** * 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. * * @param t The child to add. */ addChild(t?: CommonTree): void; /** * Adds all elements of kids list as children of this node. * * @param kids The children to add. */ addChildren(kids: CommonTree[]): void; setChild(i: number, t: CommonTree): 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. * * @param i The index to insert the child at. * @param t The child to insert. */ insertChild(i: number, t: CommonTree): void; deleteChild(i: number): CommonTree | null; /** * 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. * * @param startChildIndex The index to start deleting children. * @param stopChildIndex The index to stop deleting children. * @param t The tree to replace the deleted children with. */ replaceChildren(startChildIndex: number, stopChildIndex: number, t: CommonTree): void; /** * Sets the parent and child index values for all child of t. * * @param offset The index to start from. */ freshenParentAndChildIndexes(offset?: number): void; sanityCheckParentAndChildIndexes(): void; sanityCheckParentAndChildIndexes(parent: CommonTree | undefined, i: number): void; isNil(): boolean; getType(): number; getText(): string; getLine(): number; getCharPositionInLine(): number; getTokenStartIndex(): number; setTokenStartIndex(index: number): void; getTokenStopIndex(): number; setTokenStopIndex(index: number): 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. */ setUnknownTokenBoundaries(): void; toString(): string; getSourceInterval(): Interval; /** * Walks upwards and get first ancestor with this token type. * * @param ttype The token type to check for. * * @returns The first ancestor of this node with the specified token type, or `null` if no ancestor with * the type exists. */ getAncestor(ttype: number): CommonTree | null; /** * Prints out a whole tree not just a node. * * @returns A string representation of the tree. */ toStringTree(): string; /** * @returns 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. */ protected getAncestors(): CommonTree[] | null; }