Package org.antlr.runtime.tree
Interface Tree
- All Known Implementing Classes:
ANTLRParser.GrammarASTErrorNode
,BaseTree
,CommonErrorNode
,CommonTree
,GrammarAST
,ParseTree
,RemoteDebugEventSocketListener.ProxyTree
,TreeWizard.TreePattern
,TreeWizard.WildcardTreePattern
public interface Tree
What does a tree look like? ANTLR has a number of support classes
such as CommonTreeNodeStream that work on these kinds of trees. You
don't have to make your trees implement this interface, but if you do,
you'll be able to use more support code.
NOTE: When constructing trees, ANTLR can build any kind of tree; it can
even use Token objects as trees if you add a child list to your tokens.
This is a tree node without any payload; just navigation and factory stuff.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add t as a child to this node.deleteChild
(int i) dupNode()
void
Set the parent and child index values for all childrengetAncestor
(int ttype) Walk upwards and get first ancestor with this token type.List
<?> Return a list of all ancestors of this node.int
getChild
(int i) int
int
This node is what child index? 0..n-1int
getLine()
In case we don't have a token payload, what is the line for errors?getText()
int
What is the smallest token index (indexing from 0) for this node and its children?int
What is the largest token index (indexing from 0) for this node and its children?int
getType()
Return a token type; needed for tree parsingboolean
hasAncestor
(int ttype) Is there is a node above with token type ttype?boolean
isNil()
Indicates the node is a nil node but may still have children, meaning the tree is a flat list.void
replaceChildren
(int startChildIndex, int stopChildIndex, Object t) Delete children from start to stop and replace with t even if t is a list (nil-root tree).void
Set ith child (0..n-1) to t; t must be non-null and non-nil nodevoid
setChildIndex
(int index) void
void
setTokenStartIndex
(int index) void
setTokenStopIndex
(int index) toString()
-
Field Details
-
INVALID_NODE
-
-
Method Details
-
getChild
-
getChildCount
int getChildCount() -
getParent
Tree getParent() -
setParent
-
hasAncestor
boolean hasAncestor(int ttype) Is there is a node above with token type ttype? -
getAncestor
Walk upwards and get first ancestor with this token type. -
getAncestors
List<?> 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. -
getChildIndex
int getChildIndex()This node is what child index? 0..n-1 -
setChildIndex
void setChildIndex(int index) -
freshenParentAndChildIndexes
void freshenParentAndChildIndexes()Set the parent and child index values for all children -
addChild
Add t as a child to this node. If t is null, do nothing. If t is nil, add all children of t to this' children. -
setChild
Set ith child (0..n-1) to t; t must be non-null and non-nil node -
deleteChild
-
replaceChildren
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. -
isNil
boolean isNil()Indicates the node is a nil node but may still have children, meaning the tree is a flat list. -
getTokenStartIndex
int getTokenStartIndex()What is the smallest token index (indexing from 0) for this node and its children? -
setTokenStartIndex
void setTokenStartIndex(int index) -
getTokenStopIndex
int getTokenStopIndex()What is the largest token index (indexing from 0) for this node and its children? -
setTokenStopIndex
void setTokenStopIndex(int index) -
dupNode
Tree dupNode() -
getType
int getType()Return a token type; needed for tree parsing -
getText
String getText() -
getLine
int getLine()In case we don't have a token payload, what is the line for errors? -
getCharPositionInLine
int getCharPositionInLine() -
toStringTree
String toStringTree() -
toString
String toString()
-