|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.antlr.runtime.tree.UnBufferedTreeNodeStream
public class UnBufferedTreeNodeStream
A stream of tree nodes, accessing nodes from a tree of ANY kind. No new nodes should be created in tree during the walk. A small buffer of tokens is kept to efficiently and easily handle LT(i) calls, though the lookahead mechanism is fairly complicated. For tree rewriting during tree parsing, this must also be able to replace a set of children without "losing its place". That part is not yet implemented. Will permit a rule to return a different tree and have it stitched into the output tree probably.
CommonTreeNodeStream| Nested Class Summary | |
|---|---|
protected class |
UnBufferedTreeNodeStream.TreeWalkState
When walking ahead with cyclic DFA or for syntactic predicates, we need to record the state of the tree node stream. |
| Field Summary | |
|---|---|
protected int |
absoluteNodeIndex
What node index did we just consume? i=0..n-1 for n node trees. |
protected int |
currentChildIndex
Which child are we currently visiting? If -1 we have not visited this node yet; next consume() request will set currentIndex to 0. |
protected java.lang.Object |
currentNode
Which node are we currently visiting? |
protected java.lang.Object |
down
|
protected java.lang.Object |
eof
|
protected int |
head
lookahead[head] is the first symbol of lookahead, LT(1). |
protected java.util.Stack |
indexStack
Track which child index you are visiting for each node we push. |
static int |
INITIAL_LOOKAHEAD_BUFFER_SIZE
|
protected int |
lastMarker
Track the last mark() call result value for use in rewind(). |
protected java.lang.Object[] |
lookahead
Buffer tree node stream for use with LT(i). |
protected int |
markDepth
tracks how deep mark() calls are nested |
protected java.util.List |
markers
Calls to mark() may be nested so we have to track a stack of them. |
protected java.util.Stack |
nodeStack
As we walk down the nodes, we must track parent nodes so we know where to go after walking the last child of a node. |
protected java.lang.Object |
previousNode
Which node did we visit last? Used for LT(-1) calls. |
protected java.lang.Object |
root
Pull nodes from which tree? |
protected int |
tail
Add new lookahead at lookahead[tail]. |
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 Summary | |
|---|---|
UnBufferedTreeNodeStream(java.lang.Object tree)
|
|
UnBufferedTreeNodeStream(TreeAdaptor adaptor,
java.lang.Object tree)
|
|
| Method Summary | |
|---|---|
protected void |
addLookahead(java.lang.Object node)
Add a node to the lookahead buffer. |
protected void |
addNavigationNode(int ttype)
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure. |
void |
consume()
|
protected void |
fill(int k)
Make sure we have at least k symbols in lookahead buffer |
java.lang.Object |
get(int i)
Get a tree node at an absolute index i; 0..n-1. |
protected int |
getLookaheadSize()
|
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. |
protected java.lang.Object |
handleRootNode()
|
boolean |
hasUniqueNavigationNodes()
|
int |
index()
Return the current input symbol index 0..n where n indicates the last symbol has been read. |
int |
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int. |
java.lang.Object |
LT(int k)
Get tree node at current input pointer + i ahead where i=1 is next node. |
int |
mark()
Record the current state of the tree walk which includes the current node and stack state as well as the lookahead buffer. |
java.lang.Object |
next()
Return the next node found during a depth-first walk of root. |
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()
|
void |
rewind()
Rewind to the input position of the last marker. |
void |
rewind(int marker)
Rewind the current state of the tree walk to the state it was in when mark() was called and it returned marker. |
void |
seek(int index)
consume() ahead until we hit index. |
void |
setTokenStream(TokenStream tokens)
|
void |
setUniqueNavigationNodes(boolean uniqueNavigationNodes)
As we flatten the tree, we use UP, DOWN nodes to represent the tree structure. |
int |
size()
Expensive to compute; recursively walk tree to find size; include navigation nodes and EOF. |
java.lang.String |
toString()
Print out the entire tree including DOWN/UP nodes. |
java.lang.String |
toString(java.lang.Object start,
java.lang.Object stop)
Return the text of all nodes from start to stop, inclusive. |
protected void |
toStringWork(java.lang.Object p,
java.lang.Object stop,
java.lang.StringBuffer buf)
|
protected java.lang.Object |
visitChild(int child)
|
protected void |
walkBackToMostRecentNodeWithUnvisitedChildren()
Walk upwards looking for a node with more children to walk. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int INITIAL_LOOKAHEAD_BUFFER_SIZE
protected boolean uniqueNavigationNodes
protected java.lang.Object root
protected TokenStream tokens
protected java.util.Stack nodeStack
protected java.util.Stack indexStack
protected java.lang.Object currentNode
protected java.lang.Object previousNode
protected int currentChildIndex
protected int absoluteNodeIndex
protected java.lang.Object[] lookahead
protected int head
protected int tail
protected java.util.List markers
protected int markDepth
protected int lastMarker
protected java.lang.Object down
protected java.lang.Object up
protected java.lang.Object eof
| Constructor Detail |
|---|
public UnBufferedTreeNodeStream(java.lang.Object tree)
public UnBufferedTreeNodeStream(TreeAdaptor adaptor,
java.lang.Object tree)
| Method Detail |
|---|
public void reset()
public java.lang.Object get(int i)
TreeNodeStream
get in interface TreeNodeStreampublic java.lang.Object LT(int k)
LT in interface TreeNodeStreampublic java.lang.Object getTreeSource()
getTreeSource in interface TreeNodeStreampublic java.lang.String getSourceName()
IntStream
getSourceName in interface IntStreampublic TokenStream getTokenStream()
TreeNodeStream
getTokenStream in interface TreeNodeStreampublic void setTokenStream(TokenStream tokens)
protected void fill(int k)
protected void addLookahead(java.lang.Object node)
public void consume()
consume in interface IntStreampublic int LA(int i)
IntStream
LA in interface IntStreampublic int mark()
mark in interface IntStreampublic void release(int marker)
IntStream
release in interface IntStreampublic void rewind(int marker)
rewind in interface IntStreampublic void rewind()
IntStream
rewind in interface IntStreampublic void seek(int index)
seek in interface IntStreampublic int index()
IntStream
index in interface IntStreampublic int size()
size in interface IntStreampublic java.lang.Object next()
protected java.lang.Object handleRootNode()
protected java.lang.Object visitChild(int child)
protected void addNavigationNode(int ttype)
protected void walkBackToMostRecentNodeWithUnvisitedChildren()
public TreeAdaptor getTreeAdaptor()
TreeNodeStream
getTreeAdaptor in interface TreeNodeStreampublic boolean hasUniqueNavigationNodes()
public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)
TreeNodeStream
setUniqueNavigationNodes in interface TreeNodeStream
public void replaceChildren(java.lang.Object parent,
int startChildIndex,
int stopChildIndex,
java.lang.Object t)
TreeNodeStream
replaceChildren in interface TreeNodeStreampublic java.lang.String toString()
toString in class java.lang.Objectprotected int getLookaheadSize()
public java.lang.String toString(java.lang.Object start,
java.lang.Object stop)
TreeNodeStream
toString in interface TreeNodeStream
protected void toStringWork(java.lang.Object p,
java.lang.Object stop,
java.lang.StringBuffer buf)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||