BaseTree Class

Namespace: Stimulsoft.Data.Expressions.Antlr.Runtime.Tree

A generic tree implementation with no payload. You must subclass to actually have any user data. ANTLR v3 uses a list of children approach instead of the child-sibling approach in v2. A flat tree (a list) is an empty node whose children represent the list. An empty, but non-null node is called “nil”.

Inheritance

Implements: ITree

Constructors

Constructor Description
constructor(ITree node) Create a new node from an existing node does nothing for BaseTree as there are no fields other than the children list, which cannot be copied as the children are not considered part of this node.

constructor(node: ITree)

Create a new node from an existing node does nothing for BaseTree as there are no fields other than the children list, which cannot be copied as the children are not considered part of this node.

Parameters

Properties

Property Type Description
childCount number  
isNil boolean  
text string  
tokenStartIndex number  
tokenStopIndex number  
type number  

Methods

Method Returns Description
addChild void > Add 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.
addChildren void Add all elements of kids list as children of this node
createChildrenList ITree[] Override in a subclass to change the impl of children list
deleteChild any  
dupNode ITree  
freshenParentAndChildIndexes void  
freshenParentAndChildIndexesDeeply void  
getAncestor ITree Walk upwards and get first ancestor with this token type.</summary>
getAncestors ITree[] Return 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.
getChild ITree  
getFirstChildWithType ITree  
hasAncestor boolean Walk upwards looking for ancestor with this token type.</summary>
implements any[]  
insertChild void Insert child t at child position i (0..n-1) by shifting children i+1..n-1 to the right one position. Set parent / indexes properly but does NOT collapse nil-rooted t’s that come in here like addChild.
replaceChildren void Delete children from start to stop and replace with t even if t is a list (nil-root tree). num of children can increase or decrease. For huge child lists, inserting children can force walking rest of children to set their childindex; could be slow.
sanityCheckParentAndChildIndexes void  
setChild void  
toString string Override to say how a node (not a tree) should look as text
toStringTree string Print out a whole tree not just a node</summary>

Method Details

addChild

addChild(t: ITree): void

Add 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


addChildren

addChildren(kids: ITree[]): void

Add all elements of kids list as children of this node

Parameters


createChildrenList

createChildrenList(): ITree[]

Override in a subclass to change the impl of children list

Returns ITree[]


deleteChild

deleteChild(i: number): any

Parameters

  • i (number)

Returns any


dupNode

dupNode(): ITree

Returns ITree


freshenParentAndChildIndexes

freshenParentAndChildIndexes(offset: any): void

Parameters

  • offset (any)

freshenParentAndChildIndexesDeeply

freshenParentAndChildIndexesDeeply(offset: any): void

Parameters

  • offset (any)

getAncestor

getAncestor(ttype: number): ITree

Walk upwards and get first ancestor with this token type.</summary>

Parameters

  • ttype (number)

Returns ITree


getAncestors

getAncestors(): ITree[]

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

Returns ITree[]


getChild

getChild(i: number): ITree

Parameters

  • i (number)

Returns ITree


getFirstChildWithType

getFirstChildWithType(type: number): ITree

Parameters

  • type (number)

Returns ITree


hasAncestor

hasAncestor(ttype: number): boolean

Walk upwards looking for ancestor with this token type.</summary>

Parameters

  • ttype (number)

Returns boolean


implements

implements(): any[]

Returns any[]


insertChild

insertChild(i: number, t: ITree): void

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

Parameters


replaceChildren

replaceChildren(startChildIndex: number, stopChildIndex: number, t: any): void

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

Parameters

  • startChildIndex (number)
  • stopChildIndex (number)
  • t (any)

sanityCheckParentAndChildIndexes

sanityCheckParentAndChildIndexes(parent: ITree, i: any): void

Parameters


setChild

setChild(i: number, t: ITree): void

Parameters


toString

toString(): string

Override to say how a node (not a tree) should look as text

Returns string


toStringTree

toStringTree(): string

Print out a whole tree not just a node</summary>

Returns string

Fields

Field Type Description
_text string  
_tokenStartIndex number  
_tokenStopIndex number  
_type number  
charPositionInLine number  
childIndex any BaseTree doesn’t track child indexes.
children ITree[] Get the children internal List; note that if you directly mess with the list, do so at your own risk.
line number  
newChildren any  
newChildren any  
newChildren any  
parent ITree BaseTree doesn’t track parent pointers.
replacingWithHowMany any  
t any  
t any