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

Hierarchy

Implements

Index

Constructors

constructor

  • 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

    Returns BaseTree

Properties

Protected _text

_text: string

Protected _tokenStartIndex

_tokenStartIndex: number

Protected _tokenStopIndex

_tokenStopIndex: number

Protected _type

_type: number

charPositionInLine

charPositionInLine: number

childIndex

childIndex: number = 0

BaseTree doesn't track child indexes.

children

children: List<ITree>

Get the children internal List; note that if you directly mess with the list, do so at your own risk.

line

line: number

parent

parent: ITree = null

BaseTree doesn't track parent pointers.

Accessors

childCount

  • get childCount(): number
  • Returns number

isNil

  • get isNil(): boolean
  • Returns boolean

text

  • get text(): string
  • set text(value: string): void
  • Returns string

  • Parameters

    • value: string

    Returns void

tokenStartIndex

  • get tokenStartIndex(): number
  • set tokenStartIndex(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

tokenStopIndex

  • get tokenStopIndex(): number
  • set tokenStopIndex(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

type

  • get type(): number
  • set type(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

Methods

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

    Returns void

addChildren

  • Add all elements of kids list as children of this node

    Parameters

    Returns void

createChildrenList

  • Override in a subclass to change the impl of children list

    Returns List<ITree>

deleteChild

  • deleteChild(i: number): any

dupNode

freshenParentAndChildIndexes

  • freshenParentAndChildIndexes(offset?: number): void
  • Set the parent and child index values for all child of t

    Parameters

    • Default value offset: number = 0

    Returns void

freshenParentAndChildIndexesDeeply

  • freshenParentAndChildIndexesDeeply(offset?: number): void
  • Parameters

    • Default value offset: number = 0

    Returns void

getAncestor

  • getAncestor(ttype: number): ITree
  • Walk upwards and get first ancestor with this token type.

    Parameters

    • ttype: number

    Returns ITree

getAncestors

  • 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 List<ITree>

getChild

  • getChild(i: number): 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.

    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

    Returns void

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

    Returns void

sanityCheckParentAndChildIndexes

  • sanityCheckParentAndChildIndexes(parent?: ITree, i?: number): void
  • Parameters

    • Default value parent: ITree = null
    • Default value i: number = -1

    Returns void

setChild

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

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

    Returns string

Generated using TypeDoc