Package org.antlr.runtime.tree
Class CommonTreeNodeStream
- java.lang.Object
-
- org.antlr.runtime.misc.FastQueue<T>
-
- org.antlr.runtime.misc.LookaheadStream<Object>
-
- org.antlr.runtime.tree.CommonTreeNodeStream
-
- All Implemented Interfaces:
IntStream
,TreeNodeStream
public class CommonTreeNodeStream extends LookaheadStream<Object> implements TreeNodeStream
-
-
Field Summary
Fields Modifier and Type Field Description protected IntArray
calls
Stack of indexes used for push/pop callsstatic int
DEFAULT_INITIAL_BUFFER_SIZE
protected boolean
hasNilRoot
Tree (nil A B C) trees like flat A B C streamsstatic int
INITIAL_CALL_STACK_SIZE
protected TreeIterator
it
The tree iterator we usingprotected int
level
Tracks tree depth.protected Object
root
Pull nodes from which tree?protected TokenStream
tokens
If this tree (root) was created from a token stream, track it.-
Fields inherited from class org.antlr.runtime.misc.LookaheadStream
eof, eofElementIndex, lastMarker, markDepth, UNINITIALIZED_EOF_ELEMENT_INDEX
-
-
Constructor Summary
Constructors Constructor Description CommonTreeNodeStream(Object tree)
CommonTreeNodeStream(TreeAdaptor adaptor, Object tree)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getSourceName()
Where are you getting symbols from? Normally, implementations will pass the buck all the way to the lexer who can ask its input stream for the file name or whatever.TokenStream
getTokenStream()
If the tree associated with this stream was created from a TokenStream, you can specify it here.TreeAdaptor
getTreeAdaptor()
What adaptor can tell me how to interpret/navigate nodes and trees.Object
getTreeSource()
Where is this stream pulling nodes from? This is not the name, but the object that provides node objects.int
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int.Object
nextElement()
Pull elements from tree iterator.int
pop()
Seek back to previous index saved during last push() call.void
push(int index)
Make stream jump to a new location, saving old location.void
replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)
Replace from start to stop child index of parent with t, which might be a list.void
reset()
Reset the tree node stream in such a way that it acts like a freshly constructed stream.void
setTokenStream(TokenStream tokens)
void
setTreeAdaptor(TreeAdaptor adaptor)
void
setUniqueNavigationNodes(boolean uniqueNavigationNodes)
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure.String
toString(Object start, Object stop)
Return the text of all nodes from start to stop, inclusive.String
toTokenTypeString()
For debugging; destructive: moves tree iterator to end.-
Methods inherited from class org.antlr.runtime.misc.LookaheadStream
consume, fill, getCurrentSymbol, index, LB, LT, mark, release, remove, rewind, rewind, seek, size, sync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.antlr.runtime.IntStream
consume, index, mark, release, rewind, rewind, seek, size
-
Methods inherited from interface org.antlr.runtime.tree.TreeNodeStream
get, LT
-
-
-
-
Field Detail
-
DEFAULT_INITIAL_BUFFER_SIZE
public static final int DEFAULT_INITIAL_BUFFER_SIZE
- See Also:
- Constant Field Values
-
INITIAL_CALL_STACK_SIZE
public static final int INITIAL_CALL_STACK_SIZE
- See Also:
- Constant Field Values
-
root
protected Object root
Pull nodes from which tree?
-
tokens
protected TokenStream tokens
If this tree (root) was created from a token stream, track it.
-
it
protected TreeIterator it
The tree iterator we using
-
calls
protected IntArray calls
Stack of indexes used for push/pop calls
-
hasNilRoot
protected boolean hasNilRoot
Tree (nil A B C) trees like flat A B C streams
-
level
protected int level
Tracks tree depth. Level=0 means we're at root node level.
-
-
Constructor Detail
-
CommonTreeNodeStream
public CommonTreeNodeStream(Object tree)
-
CommonTreeNodeStream
public CommonTreeNodeStream(TreeAdaptor adaptor, Object tree)
-
-
Method Detail
-
reset
public void reset()
Description copied from interface:TreeNodeStream
Reset the tree node stream in such a way that it acts like a freshly constructed stream.- Specified by:
reset
in interfaceTreeNodeStream
- Overrides:
reset
in classLookaheadStream<Object>
-
nextElement
public Object nextElement()
Pull elements from tree iterator. Track tree level 0..max_level. If nil rooted tree, don't give initial nil and DOWN nor final UP.- Specified by:
nextElement
in classLookaheadStream<Object>
-
setUniqueNavigationNodes
public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)
Description copied from interface:TreeNodeStream
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure. When debugging we need unique nodes so we have to instantiate new ones. When doing normal tree parsing, it's slow and a waste of memory to create unique navigation nodes. Default should be false;- Specified by:
setUniqueNavigationNodes
in interfaceTreeNodeStream
-
getTreeSource
public Object getTreeSource()
Description copied from interface:TreeNodeStream
Where is this stream pulling nodes from? This is not the name, but the object that provides node objects.- Specified by:
getTreeSource
in interfaceTreeNodeStream
-
getSourceName
public String getSourceName()
Description copied from interface:IntStream
Where are you getting symbols from? Normally, implementations will pass the buck all the way to the lexer who can ask its input stream for the file name or whatever.- Specified by:
getSourceName
in interfaceIntStream
-
getTokenStream
public TokenStream getTokenStream()
Description copied from interface:TreeNodeStream
If the tree associated with this stream was created from a TokenStream, you can specify it here. Used to do rule $text attribute in tree parser. Optional unless you use tree parser rule text attribute or output=template and rewrite=true options.- Specified by:
getTokenStream
in interfaceTreeNodeStream
-
setTokenStream
public void setTokenStream(TokenStream tokens)
-
getTreeAdaptor
public TreeAdaptor getTreeAdaptor()
Description copied from interface:TreeNodeStream
What adaptor can tell me how to interpret/navigate nodes and trees. E.g., get text of a node.- Specified by:
getTreeAdaptor
in interfaceTreeNodeStream
-
setTreeAdaptor
public void setTreeAdaptor(TreeAdaptor adaptor)
-
LA
public int LA(int i)
Description copied from interface:IntStream
Get int at current input pointer + i ahead where i=1 is next int. Negative indexes are allowed. LA(-1) is previous token (token just matched). LA(-i) where i is before first token should yield -1, invalid char / EOF.
-
push
public void push(int index)
Make stream jump to a new location, saving old location. Switch back with pop().
-
pop
public int pop()
Seek back to previous index saved during last push() call. Return top of stack (return index).
-
replaceChildren
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)
Description copied from interface:TreeNodeStream
Replace from start to stop child index of parent with t, 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 parent is null, don't do anything; must be at root of overall tree. Can't replace whatever points to the parent externally. Do nothing.- Specified by:
replaceChildren
in interfaceTreeNodeStream
-
toString
public String toString(Object start, Object stop)
Description copied from interface:TreeNodeStream
Return the text of all nodes from start to stop, inclusive. If the stream does not buffer all the nodes then it can still walk recursively from start until stop. You can always return null or "" too, but users should not access $ruleLabel.text in an action of course in that case.- Specified by:
toString
in interfaceTreeNodeStream
-
toTokenTypeString
public String toTokenTypeString()
For debugging; destructive: moves tree iterator to end.
-
-