Class CommonTree
java.lang.Object
org.antlr.runtime.tree.BaseTree
org.antlr.runtime.tree.CommonTree
- All Implemented Interfaces:
Tree
- Direct Known Subclasses:
CommonErrorNode, TreeWizard.TreePattern
A tree node that is wrapper for a Token object. After 3.0 release
while building tree rewrite stuff, it became clear that computing
parent and child index is very difficult and cumbersome. Better to
spend the space in every tree node. If you don't want these extra
fields, it's easy to cut them out in your own BaseTree subclass.
-
Field Summary
FieldsModifier and TypeFieldDescriptionintWhat index is this node in the child list? Range: 0..n-1Who is the parent node of this node; if null, implies node is rootprotected intWhat token indexes bracket all tokens associated with this node and below?protected intWhat token indexes bracket all tokens associated with this node and below?A single token is the payloadFields inherited from interface Tree
INVALID_NODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondupNode()intintBaseTree doesn't track child indexes.intgetLine()In case we don't have a token payload, what is the line for errors?BaseTree doesn't track parent pointers.getText()getToken()intWhat is the smallest token index (indexing from 0) for this node and its children?intWhat is the largest token index (indexing from 0) for this node and its children?intgetType()Return a token type; needed for tree parsingbooleanisNil()Indicates the node is a nil node but may still have children, meaning the tree is a flat list.voidsetChildIndex(int index) voidvoidsetTokenStartIndex(int index) voidsetTokenStopIndex(int index) voidFor every node in this subtree, make sure it's start/stop token's are set.toString()Override to say how a node (not a tree) should look as textMethods inherited from class BaseTree
addChild, addChildren, createChildrenList, deleteChild, freshenParentAndChildIndexes, freshenParentAndChildIndexes, freshenParentAndChildIndexesDeeply, freshenParentAndChildIndexesDeeply, getAncestor, getAncestors, getChild, getChildCount, getChildren, getFirstChildWithType, hasAncestor, insertChild, replaceChildren, sanityCheckParentAndChildIndexes, sanityCheckParentAndChildIndexes, setChild, toStringTree
-
Field Details
-
token
A single token is the payload -
startIndex
protected int startIndexWhat token indexes bracket all tokens associated with this node and below? -
stopIndex
protected int stopIndexWhat token indexes bracket all tokens associated with this node and below? -
parent
Who is the parent node of this node; if null, implies node is root -
childIndex
public int childIndexWhat index is this node in the child list? Range: 0..n-1
-
-
Constructor Details
-
CommonTree
public CommonTree() -
CommonTree
-
CommonTree
-
-
Method Details
-
getToken
-
dupNode
-
isNil
-
getType
public int getType()Description copied from interface:TreeReturn a token type; needed for tree parsing -
getText
-
getLine
-
getCharPositionInLine
public int getCharPositionInLine()- Specified by:
getCharPositionInLinein interfaceTree- Overrides:
getCharPositionInLinein classBaseTree
-
getTokenStartIndex
public int getTokenStartIndex()Description copied from interface:TreeWhat is the smallest token index (indexing from 0) for this node and its children? -
setTokenStartIndex
public void setTokenStartIndex(int index) -
getTokenStopIndex
public int getTokenStopIndex()Description copied from interface:TreeWhat is the largest token index (indexing from 0) for this node and its children? -
setTokenStopIndex
public void setTokenStopIndex(int index) -
setUnknownTokenBoundaries
public void setUnknownTokenBoundaries()For every node in this subtree, make sure it's start/stop token's are set. Walk depth first, visit bottom up. Only updates nodes with at least one token index < 0. -
getChildIndex
public int getChildIndex()Description copied from class:BaseTreeBaseTree doesn't track child indexes.- Specified by:
getChildIndexin interfaceTree- Overrides:
getChildIndexin classBaseTree
-
getParent
-
setParent
-
setChildIndex
public void setChildIndex(int index) - Specified by:
setChildIndexin interfaceTree- Overrides:
setChildIndexin classBaseTree
-
toString
-