Package org.antlr.runtime.tree
Interface TreeNodeStream
- All Superinterfaces:
IntStream
- All Known Implementing Classes:
BufferedTreeNodeStream,CommonTreeNodeStream,DebugTreeNodeStream
A stream of tree nodes, accessing nodes from a tree of some kind
-
Method Summary
Modifier and TypeMethodDescriptionget(int i) Get a tree node at an absolute indexi; 0..n-1.If the tree associated with this stream was created from aTokenStream, you can specify it here.What adaptor can tell me how to interpret/navigate nodes and trees.Where is this stream pulling nodes from? This is not the name, but the object that provides node objects.LT(int k) Get tree node at current input pointer +kahead wherek==1is next node.voidreplaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) Replace children ofparentfrom indexstartChildIndextostopChildIndexwitht, which might be a list.voidreset()Reset the tree node stream in such a way that it acts like a freshly constructed stream.voidsetUniqueNavigationNodes(boolean uniqueNavigationNodes) As we flatten the tree, we useToken.UP,Token.DOWNnodes to represent the tree structure.Return the text of all nodes fromstarttostop, inclusive.
-
Method Details
-
get
Get a tree node at an absolute indexi; 0..n-1. If you don't want to buffer up nodes, then this method makes no sense for you. -
LT
Get tree node at current input pointer +kahead wherek==1is next node.k<0indicates nodes in the past. SoLT(-1)is previous node, but implementations are not required to provide results fork < -1.LT(0)is undefined. Fork<=n, returnnull. ReturnnullforLT(0)and any index that results in an absolute address that is negative.This is analogous to
TokenStream.LT(int), but this returns a tree node instead of aToken. Makes code generation identical for both parser and tree grammars. -
getTreeSource
Object getTreeSource()Where is this stream pulling nodes from? This is not the name, but the object that provides node objects. -
getTokenStream
TokenStream getTokenStream()If the tree associated with this stream was created from aTokenStream, you can specify it here. Used to do rule$textattribute in tree parser. Optional unless you use tree parser rule$textattribute oroutput=templateandrewrite=trueoptions. -
getTreeAdaptor
TreeAdaptor getTreeAdaptor()What adaptor can tell me how to interpret/navigate nodes and trees. E.g., get text of a node. -
reset
void reset()Reset the tree node stream in such a way that it acts like a freshly constructed stream. -
toString
Return the text of all nodes fromstarttostop, inclusive. If the stream does not buffer all the nodes then it can still walk recursively from start until stop. You can always returnnullor""too, but users should not access$ruleLabel.textin an action of course in that case. -
replaceChildren
Replace children ofparentfrom indexstartChildIndextostopChildIndexwitht, which might be a list. Number of children may be different after this call. The stream is notified because it is walking the tree and might need to know you are monkeying with the underlying tree. Also, it might be able to modify the node stream to avoid restreaming for future phases.If
parentisnull, don't do anything; must be at root of overall tree. Can't replace whatever points to the parent externally. Do nothing.
-