public class BufferedTreeNodeStream extends 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 Object |
down |
protected Object |
eof |
static int |
INITIAL_CALL_STACK_SIZE |
protected int |
lastMarker
Track the last mark() call result value for use in rewind().
|
protected 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 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 Object |
up |
Constructor and Description |
---|
BufferedTreeNodeStream(Object tree) |
BufferedTreeNodeStream(TreeAdaptor adaptor,
Object tree) |
BufferedTreeNodeStream(TreeAdaptor adaptor,
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(Object t) |
Object |
get(int i)
Get a tree node at an absolute index i; 0..n-1.
|
Object |
getCurrentSymbol() |
protected int |
getNodeIndex(Object node)
What is the stream index for node? 0..n-1
Return -1 if node not found.
|
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 |
hasUniqueNavigationNodes() |
int |
index()
Return the current input symbol index 0..n where n indicates the
last symbol has been read.
|
Iterator |
iterator() |
int |
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int.
|
protected Object |
LB(int k)
Look backwards k nodes
|
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(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 |
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.
|
String |
toString(Object start,
Object stop)
Return the text of all nodes from start to stop, inclusive.
|
String |
toTokenString(int start,
int stop)
Debugging
|
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 Object down
protected Object up
protected Object eof
protected List nodes
protected Object root
protected TokenStream tokens
protected boolean uniqueNavigationNodes
protected int p
protected int lastMarker
protected IntArray calls
public BufferedTreeNodeStream(Object tree)
public BufferedTreeNodeStream(TreeAdaptor adaptor, Object tree)
public BufferedTreeNodeStream(TreeAdaptor adaptor, Object tree, int initialBufferSize)
protected void fillBuffer()
public void fillBuffer(Object t)
protected int getNodeIndex(Object node)
protected void addNavigationNode(int ttype)
public Object get(int i)
TreeNodeStream
get
in interface TreeNodeStream
public Object LT(int k)
TreeNodeStream
LT
in interface TreeNodeStream
public Object getCurrentSymbol()
protected Object LB(int k)
public Object getTreeSource()
TreeNodeStream
getTreeSource
in interface TreeNodeStream
public 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 Iterator iterator()
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)
TreeNodeStream
replaceChildren
in interface TreeNodeStream
public String toTokenTypeString()
public String toTokenString(int start, int stop)
public String toString(Object start, Object stop)
TreeNodeStream
toString
in interface TreeNodeStream
Copyright © 2020. All rights reserved.