Package org.antlr.runtime.tree
Class CommonTreeNodeStream
- All Implemented Interfaces:
IntStream
,PositionTrackingStream<Object>
,TreeNodeStream
public class CommonTreeNodeStream
extends LookaheadStream<Object>
implements TreeNodeStream, PositionTrackingStream<Object>
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) TreeAdaptor
WhatTreeAdaptor
was used to build these treesprotected IntArray
Stack of indexes used for push/pop calls.static final int
protected boolean
Tree(nil A B C)
trees like flatA B C
streamsstatic final int
protected TreeIterator
TheTreeIterator
we using.protected int
Tracks tree depth.protected Object
Tracks the last node before the start ofFastQueue.data
which contains position information to provide information for error reporting.protected Object
Pull nodes from which tree?protected TokenStream
If this tree (root) was created from aTokenStream
, track it.Fields inherited from class org.antlr.runtime.misc.LookaheadStream
currentElementIndex, eof, lastMarker, markDepth, prevElement, UNINITIALIZED_EOF_ELEMENT_INDEX
-
Constructor Summary
ConstructorsConstructorDescriptionCommonTreeNodeStream
(Object tree) CommonTreeNodeStream
(TreeAdaptor adaptor, Object tree) -
Method Summary
Modifier and TypeMethodDescriptionget
(int i) Get a tree node at an absolute indexi
; 0..n-1.getKnownPositionElement
(boolean allowApproximateLocation) Returns an element containing position information.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.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.boolean
hasPositionInformation
(Object node) Determines if the specifiedelement
contains concrete position information.boolean
int
LA
(int i) Get int at current input pointer + i ahead where i=1 is next int.Pull elements from tree iterator.int
pop()
Seek back to previous index saved during lastpush(int)
call.void
push
(int index) Make stream jump to a new location, saving old location.remove()
Get and remove first element in queue; overrideFastQueue.remove()
; it's the same, just checks for backtracking.void
replaceChildren
(Object parent, int startChildIndex, int stopChildIndex, Object t) Replace children ofparent
from indexstartChildIndex
tostopChildIndex
witht
, 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 useToken.UP
,Token.DOWN
nodes to represent the tree structure.Return the text of all nodes fromstart
tostop
, inclusive.For debugging; destructive: moves tree iterator to end.Methods inherited from class org.antlr.runtime.misc.LookaheadStream
consume, fill, index, LB, LT, mark, release, rewind, rewind, seek, size, syncAhead
Methods inherited from class org.antlr.runtime.misc.FastQueue
add, clear, elementAt, head, range, toString
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
LT
-
Field Details
-
DEFAULT_INITIAL_BUFFER_SIZE
public static final int DEFAULT_INITIAL_BUFFER_SIZE- See Also:
-
INITIAL_CALL_STACK_SIZE
public static final int INITIAL_CALL_STACK_SIZE- See Also:
-
root
Pull nodes from which tree? -
tokens
If this tree (root) was created from aTokenStream
, track it. -
adaptor
TreeAdaptor adaptorWhatTreeAdaptor
was used to build these trees -
it
TheTreeIterator
we using. -
calls
Stack of indexes used for push/pop calls. -
hasNilRoot
protected boolean hasNilRootTree(nil A B C)
trees like flatA B C
streams -
level
protected int levelTracks tree depth. Level=0 means we're at root node level. -
previousLocationElement
Tracks the last node before the start ofFastQueue.data
which contains position information to provide information for error reporting. This is tracked in addition toLookaheadStream.prevElement
which may or may not contain position information.- See Also:
-
-
Constructor Details
-
CommonTreeNodeStream
-
CommonTreeNodeStream
-
-
Method Details
-
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
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>
- See Also:
-
remove
Description copied from class:LookaheadStream
Get and remove first element in queue; overrideFastQueue.remove()
; it's the same, just checks for backtracking.- Overrides:
remove
in classLookaheadStream<Object>
-
isEOF
- Specified by:
isEOF
in classLookaheadStream<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
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
Description copied from interface:TreeNodeStream
If the tree associated with this stream was created from aTokenStream
, you can specify it here. Used to do rule$text
attribute in tree parser. Optional unless you use tree parser rule$text
attribute oroutput=template
andrewrite=true
options.- Specified by:
getTokenStream
in interfaceTreeNodeStream
-
setTokenStream
-
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
-
get
Description copied from interface:TreeNodeStream
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.- Specified by:
get
in interfaceTreeNodeStream
-
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 lastpush(int)
call. Return top of stack (return index). -
getKnownPositionElement
Returns an element containing position information. IfallowApproximateLocation
isfalse
, then this method will return theLT(1)
element if it contains position information, and otherwise returnnull
. IfallowApproximateLocation
istrue
, then this method will return the last known element containing position information.- Specified by:
getKnownPositionElement
in interfacePositionTrackingStream<Object>
- Parameters:
allowApproximateLocation
- iffalse
, this method returnsnull
if an element containing exact information about the current position is not available- See Also:
-
hasPositionInformation
Description copied from interface:PositionTrackingStream
Determines if the specifiedelement
contains concrete position information.- Specified by:
hasPositionInformation
in interfacePositionTrackingStream<Object>
- Parameters:
node
- the element to check- Returns:
true
ifelement
contains concrete position information, otherwisefalse
-
replaceChildren
Description copied from interface:TreeNodeStream
Replace children ofparent
from indexstartChildIndex
tostopChildIndex
witht
, 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
isnull
, 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
Description copied from interface:TreeNodeStream
Return the text of all nodes fromstart
tostop
, inclusive. If the stream does not buffer all the nodes then it can still walk recursively from start until stop. You can always returnnull
or""
too, but users should not access$ruleLabel.text
in an action of course in that case.- Specified by:
toString
in interfaceTreeNodeStream
-
toTokenTypeString
For debugging; destructive: moves tree iterator to end.
-