public class BufferedTreeNodeStream extends java.lang.Object implements TreeNodeStream
CommonTreeNodeStream
Modifier and Type | Class and Description |
---|---|
protected class |
BufferedTreeNodeStream.StreamIterator |
Modifier and Type | Field and Description |
---|---|
protected IntArray |
calls
Stack of indexes used for push/pop calls
|
static int |
DEFAULT_INITIAL_BUFFER_SIZE |
protected java.lang.Object |
down |
protected java.lang.Object |
eof |
static int |
INITIAL_CALL_STACK_SIZE |
protected int |
lastMarker
Track the last mark() call result value for use in rewind().
|
protected java.util.List |
nodes
The complete mapping from stream index to tree node.
|
protected int |
p
The index into the nodes list of the current node (next node
to consume).
|
protected java.lang.Object |
root
Pull nodes from which tree?
|
protected TokenStream |
tokens
IF this tree (root) was created from a token stream, track it.
|
protected boolean |
uniqueNavigationNodes
Reuse same DOWN, UP navigation nodes unless this is true
|
protected java.lang.Object |
up |
Constructor and Description |
---|
BufferedTreeNodeStream(java.lang.Object tree) |
BufferedTreeNodeStream(TreeAdaptor adaptor,
java.lang.Object tree) |
BufferedTreeNodeStream(TreeAdaptor adaptor,
java.lang.Object tree,
int initialBufferSize) |
Modifier and Type | Method and Description |
---|---|
protected void |
addNavigationNode(int ttype)
As we flatten the tree, we use UP, DOWN nodes to represent
the tree structure.
|
void |
consume() |
protected void |
fillBuffer()
Walk tree with depth-first-search and fill nodes buffer.
|
void |
fillBuffer(java.lang.Object t) |
java.lang.Object |
get(int i)
Get a tree node at an absolute index i; 0..n-1.
|
java.lang.Object |
getCurrentSymbol() |
protected int |
getNodeIndex(java.lang.Object node)
What is the stream index for node? 0..n-1
Return -1 if node not found.
|
java.lang.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.
|
java.lang.Object |
getTreeSource()
Where is this stream pulling nodes from? This is not the name, but
the object that provides node objects.
|
boolean |
hasUniqueNavigationNodes() |
int |
index()
Return the current input symbol index 0..n where n indicates the
last symbol has been read.
|
java.util.Iterator |
iterator() |
int |
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int.
|
protected java.lang.Object |
LB(int k)
Look backwards k nodes
|
java.lang.Object |
LT(int k)
Get tree node at current input pointer + i ahead where i=1 is next node.
|
int |
mark()
Tell the stream to start buffering if it hasn't already.
|
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 |
release(int marker)
You may want to commit to a backtrack but don't want to force the
stream to keep bookkeeping objects around for a marker that is
no longer necessary.
|
void |
replaceChildren(java.lang.Object parent,
int startChildIndex,
int stopChildIndex,
java.lang.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 |
rewind()
Rewind to the input position of the last marker.
|
void |
rewind(int marker)
Reset the stream so that next call to index would return marker.
|
void |
seek(int index)
Set the input cursor to the position indicated by index.
|
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.
|
int |
size()
Only makes sense for streams that buffer everything up probably, but
might be useful to display the entire stream or for testing.
|
java.lang.String |
toString(java.lang.Object start,
java.lang.Object stop)
Return the text of all nodes from start to stop, inclusive.
|
java.lang.String |
toTokenString(int start,
int stop)
Debugging
|
java.lang.String |
toTokenTypeString()
Used for testing, just return the token type stream
|
public static final int DEFAULT_INITIAL_BUFFER_SIZE
public static final int INITIAL_CALL_STACK_SIZE
protected java.lang.Object down
protected java.lang.Object up
protected java.lang.Object eof
protected java.util.List nodes
protected java.lang.Object root
protected TokenStream tokens
protected boolean uniqueNavigationNodes
protected int p
protected int lastMarker
protected IntArray calls
public BufferedTreeNodeStream(java.lang.Object tree)
public BufferedTreeNodeStream(TreeAdaptor adaptor, java.lang.Object tree)
public BufferedTreeNodeStream(TreeAdaptor adaptor, java.lang.Object tree, int initialBufferSize)
protected void fillBuffer()
public void fillBuffer(java.lang.Object t)
protected int getNodeIndex(java.lang.Object node)
protected void addNavigationNode(int ttype)
public java.lang.Object get(int i)
TreeNodeStream
get
in interface TreeNodeStream
public java.lang.Object LT(int k)
TreeNodeStream
LT
in interface TreeNodeStream
public java.lang.Object getCurrentSymbol()
protected java.lang.Object LB(int k)
public java.lang.Object getTreeSource()
TreeNodeStream
getTreeSource
in interface TreeNodeStream
public java.lang.String getSourceName()
IntStream
getSourceName
in interface IntStream
public TokenStream getTokenStream()
TreeNodeStream
getTokenStream
in interface TreeNodeStream
public void setTokenStream(TokenStream tokens)
public TreeAdaptor getTreeAdaptor()
TreeNodeStream
getTreeAdaptor
in interface TreeNodeStream
public void setTreeAdaptor(TreeAdaptor adaptor)
public boolean hasUniqueNavigationNodes()
public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)
TreeNodeStream
setUniqueNavigationNodes
in interface TreeNodeStream
public int LA(int i)
IntStream
public int mark()
IntStream
public void release(int marker)
IntStream
public int index()
IntStream
public void rewind(int marker)
IntStream
public void rewind()
IntStream
public void seek(int index)
IntStream
public void push(int index)
public int pop()
public void reset()
TreeNodeStream
reset
in interface TreeNodeStream
public int size()
IntStream
public java.util.Iterator iterator()
public void replaceChildren(java.lang.Object parent, int startChildIndex, int stopChildIndex, java.lang.Object t)
TreeNodeStream
replaceChildren
in interface TreeNodeStream
public java.lang.String toTokenTypeString()
public java.lang.String toTokenString(int start, int stop)
public java.lang.String toString(java.lang.Object start, java.lang.Object stop)
TreeNodeStream
toString
in interface TreeNodeStream
Copyright © 2013. All Rights Reserved.