public class CommonTreeNodeStream extends LookaheadStream<Object> implements TreeNodeStream, PositionTrackingStream<Object>
Modifier and Type | Field and Description |
---|---|
protected IntArray |
calls
Stack of indexes used for push/pop calls.
|
static int |
DEFAULT_INITIAL_BUFFER_SIZE |
protected boolean |
hasNilRoot
Tree
(nil A B C) trees like flat A B C streams |
static int |
INITIAL_CALL_STACK_SIZE |
protected TreeIterator |
it
The
TreeIterator we using. |
protected int |
level
Tracks tree depth.
|
protected Object |
previousLocationElement
Tracks the last node before the start of
FastQueue.data which contains
position information to provide information for error reporting. |
protected Object |
root
Pull nodes from which tree?
|
protected TokenStream |
tokens
If this tree (root) was created from a
TokenStream , track it. |
currentElementIndex, eof, lastMarker, markDepth, prevElement, UNINITIALIZED_EOF_ELEMENT_INDEX
Constructor and Description |
---|
CommonTreeNodeStream(Object tree) |
CommonTreeNodeStream(TreeAdaptor adaptor,
Object tree) |
Modifier and Type | Method and Description |
---|---|
Object |
get(int i)
Get a tree node at an absolute index
i ; 0..n-1. |
Object |
getKnownPositionElement(boolean allowApproximateLocation)
Returns an element containing position information.
|
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.
|
boolean |
hasPositionInformation(Object node)
Determines if the specified
element contains concrete position
information. |
boolean |
isEOF(Object o) |
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(int) call. |
void |
push(int index)
Make stream jump to a new location, saving old location.
|
Object |
remove()
Get and remove first element in queue; override
FastQueue.remove() ; it's the same, just checks for backtracking. |
void |
replaceChildren(Object parent,
int startChildIndex,
int stopChildIndex,
Object t)
Replace children of
parent from index startChildIndex to
stopChildIndex 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
Token.UP , Token.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.
|
consume, fill, index, LB, LT, mark, release, rewind, rewind, seek, size, syncAhead
add, clear, elementAt, head, range, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
LT
public static final int DEFAULT_INITIAL_BUFFER_SIZE
public static final int INITIAL_CALL_STACK_SIZE
protected Object root
protected TokenStream tokens
TokenStream
, track it.protected TreeIterator it
TreeIterator
we using.protected IntArray calls
protected boolean hasNilRoot
(nil A B C)
trees like flat A B C
streamsprotected int level
protected Object previousLocationElement
FastQueue.data
which contains
position information to provide information for error reporting. This is
tracked in addition to LookaheadStream.prevElement
which may or may not contain
position information.public CommonTreeNodeStream(Object tree)
public CommonTreeNodeStream(TreeAdaptor adaptor, Object tree)
public void reset()
TreeNodeStream
reset
in interface TreeNodeStream
reset
in class LookaheadStream<Object>
public Object nextElement()
nextElement
in class LookaheadStream<Object>
LookaheadStream.isEOF(T)
public Object remove()
LookaheadStream
FastQueue.remove()
; it's the same, just checks for backtracking.remove
in class LookaheadStream<Object>
public boolean isEOF(Object o)
isEOF
in class LookaheadStream<Object>
public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)
TreeNodeStream
Token.UP
, Token.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
.setUniqueNavigationNodes
in interface TreeNodeStream
public Object getTreeSource()
TreeNodeStream
getTreeSource
in interface TreeNodeStream
public String getSourceName()
IntStream
getSourceName
in interface IntStream
public TokenStream getTokenStream()
TreeNodeStream
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.getTokenStream
in interface TreeNodeStream
public void setTokenStream(TokenStream tokens)
public TreeAdaptor getTreeAdaptor()
TreeNodeStream
getTreeAdaptor
in interface TreeNodeStream
public void setTreeAdaptor(TreeAdaptor adaptor)
public Object get(int i)
TreeNodeStream
i
; 0..n-1.
If you don't want to buffer up nodes, then this method makes no
sense for you.get
in interface TreeNodeStream
public int LA(int i)
IntStream
public void push(int index)
public int pop()
push(int)
call.
Return top of stack (return index).public Object getKnownPositionElement(boolean allowApproximateLocation)
allowApproximateLocation
is false
, then
this method will return the LT(1)
element if it contains position information, and otherwise return null
.
If allowApproximateLocation
is true
, then this method will return the last known element containing position information.getKnownPositionElement
in interface PositionTrackingStream<Object>
allowApproximateLocation
- if false
, this method returns
null
if an element containing exact information about the current
position is not availablehasPositionInformation(java.lang.Object)
public boolean hasPositionInformation(Object node)
PositionTrackingStream
element
contains concrete position
information.hasPositionInformation
in interface PositionTrackingStream<Object>
node
- the element to checktrue
if element
contains concrete position
information, otherwise false
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)
TreeNodeStream
parent
from index startChildIndex
to
stopChildIndex
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.
replaceChildren
in interface TreeNodeStream
public String toString(Object start, Object stop)
TreeNodeStream
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.toString
in interface TreeNodeStream
public String toTokenTypeString()
Copyright © 1992–2015 ANTLR. All rights reserved.