Top Fields Constructors Methods
org.antlr.runtime.tree

public Class CommonTreeNodeStream

extends LookaheadStream<Object>
implements TreeNodeStream, PositionTrackingStream<Object>
Class Inheritance
All Implemented Interfaces
org.antlr.runtime.tree.PositionTrackingStream, org.antlr.runtime.tree.TreeNodeStream, org.antlr.runtime.IntStream
Imports
org.antlr.runtime.RecognitionException, .Token, .TokenStream, org.antlr.runtime.misc.LookaheadStream, .IntArray

Field Summary

Modifier and TypeField and Description
pack-priv TreeAdaptor
adaptor

What TreeAdaptor was used to build these trees

protected IntArray
calls

Stack of indexes used for push/pop calls.

public static final int
protected boolean
hasNilRoot

Tree (nil A B C) trees like flat A B C streams

public static final int
protected TreeIterator
it

The TreeIterator we using.

protected int
level

Tracks tree depth.

protected Object
previousLocationElement

Tracks the last node before the start of 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.

Inherited from org.antlr.runtime.misc.LookaheadStream:
currentElementIndexeoflastMarkermarkDepthprevElementUNINITIALIZED_EOF_ELEMENT_INDEX

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public Object
get(int i)

Implements org.antlr.runtime.tree.TreeNodeStream.get.

Get a tree node at an absolute index i; 0..n-1.
public Object
getKnownPositionElement(boolean
if false, this method returns null if an element containing exact information about the current position is not available
allowApproximateLocation
)

Implements org.antlr.runtime.tree.PositionTrackingStream.getKnownPositionElement.

Returns an element containing position information.
public String
getSourceName()

Implements org.antlr.runtime.IntStream.getSourceName.

Where are you getting symbols from?
public TokenStream
getTokenStream()

Implements org.antlr.runtime.tree.TreeNodeStream.getTokenStream.

If the tree associated with this stream was created from a TokenStream, you can specify it here.
public TreeAdaptor
getTreeAdaptor()

Implements org.antlr.runtime.tree.TreeNodeStream.getTreeAdaptor.

What adaptor can tell me how to interpret/navigate nodes and trees.
public Object
getTreeSource()

Implements org.antlr.runtime.tree.TreeNodeStream.getTreeSource.

Where is this stream pulling nodes from?
public boolean
hasPositionInformation(Object
the element to check
node
)

Implements org.antlr.runtime.tree.PositionTrackingStream.hasPositionInformation.

Determines if the specified element contains concrete position information.
public boolean
public int
LA(int i)

Implements org.antlr.runtime.IntStream.LA.

Get int at current input pointer + i ahead where i=1 is next int.
public Object
nextElement()

Implements abstract org.antlr.runtime.misc.LookaheadStream.nextElement.

Pull elements from tree iterator.
public int
pop()

Seek back to previous index saved during last push call.

public void
push(int index)

Make stream jump to a new location, saving old location.

public Object
remove()

Overrides org.antlr.runtime.misc.LookaheadStream.remove.

Get and remove first element in queue; override FastQueue#remove(); it's the same, just checks for backtracking.
public void
replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)

Implements org.antlr.runtime.tree.TreeNodeStream.replaceChildren.

Replace children of parent from index startChildIndex to stopChildIndex with t, which might be a list.
public void
reset()

Overrides org.antlr.runtime.misc.LookaheadStream.reset.

Implements org.antlr.runtime.tree.TreeNodeStream.reset.

Reset the tree node stream in such a way that it acts like a freshly constructed stream.
public void
public void
public void
setUniqueNavigationNodes(boolean uniqueNavigationNodes)

Implements org.antlr.runtime.tree.TreeNodeStream.setUniqueNavigationNodes.

As we flatten the tree, we use Token#UP, Token#DOWN nodes to represent the tree structure.
public String
toString(Object start, Object stop)

Implements org.antlr.runtime.tree.TreeNodeStream.toString.

Return the text of all nodes from start to stop, inclusive.
public String
toTokenTypeString()

For debugging; destructive: moves tree iterator to end.

Inherited from org.antlr.runtime.misc.LookaheadStream:
consumefillindexLBLTmarkreleaserewindrewindseeksizesyncAhead

Field Detail

adaptorback to summary
pack-priv TreeAdaptor adaptor

What TreeAdaptor was used to build these trees

callsback to summary
protected IntArray calls

Stack of indexes used for push/pop calls.

DEFAULT_INITIAL_BUFFER_SIZEback to summary
public static final int DEFAULT_INITIAL_BUFFER_SIZE
hasNilRootback to summary
protected boolean hasNilRoot

Tree (nil A B C) trees like flat A B C streams

INITIAL_CALL_STACK_SIZEback to summary
public static final int INITIAL_CALL_STACK_SIZE
itback to summary
protected TreeIterator it

The TreeIterator we using.

levelback to summary
protected int level

Tracks tree depth. Level=0 means we're at root node level.

previousLocationElementback to summary
protected Object previousLocationElement

Tracks the last node before the start of data which contains position information to provide information for error reporting. This is tracked in addition to prevElement which may or may not contain position information.

See Also
hasPositionInformation, RecognitionException#extractInformationFromTreeNodeStream
rootback to summary
protected Object root

Pull nodes from which tree?

tokensback to summary
protected TokenStream tokens

If this tree (root) was created from a TokenStream, track it.

Constructor Detail

CommonTreeNodeStreamback to summary
public CommonTreeNodeStream(Object tree)
CommonTreeNodeStreamback to summary
public CommonTreeNodeStream(TreeAdaptor adaptor, Object tree)

Method Detail

getback to summary
public Object get(int i)

Implements org.antlr.runtime.tree.TreeNodeStream.get.

Doc from org.antlr.runtime.tree.TreeNodeStream.get.

Get a tree node at an absolute index i; 0..n-1. If you don't want to buffer up nodes, then this method makes no sense for you.

Annotations
@Override
getKnownPositionElementback to summary
public Object getKnownPositionElement(boolean allowApproximateLocation)

Implements org.antlr.runtime.tree.PositionTrackingStream.getKnownPositionElement.

Returns an element containing position information. If 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.

Parameters
allowApproximateLocation:boolean

Doc from org.antlr.runtime.tree.PositionTrackingStream.getKnownPositionElement.

if false, this method returns null if an element containing exact information about the current position is not available

Annotations
@Override
See Also
hasPositionInformation
getSourceNameback to summary
public String getSourceName()

Implements org.antlr.runtime.IntStream.getSourceName.

Doc from org.antlr.runtime.IntStream.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.

Annotations
@Override
getTokenStreamback to summary
public TokenStream getTokenStream()

Implements org.antlr.runtime.tree.TreeNodeStream.getTokenStream.

Doc from org.antlr.runtime.tree.TreeNodeStream.getTokenStream.

If the tree associated with this stream was created from a 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.

Annotations
@Override
getTreeAdaptorback to summary
public TreeAdaptor getTreeAdaptor()

Implements org.antlr.runtime.tree.TreeNodeStream.getTreeAdaptor.

Doc from org.antlr.runtime.tree.TreeNodeStream.getTreeAdaptor.

What adaptor can tell me how to interpret/navigate nodes and trees. E.g., get text of a node.

Annotations
@Override
getTreeSourceback to summary
public Object getTreeSource()

Implements org.antlr.runtime.tree.TreeNodeStream.getTreeSource.

Doc from org.antlr.runtime.tree.TreeNodeStream.getTreeSource.

Where is this stream pulling nodes from? This is not the name, but the object that provides node objects.

Annotations
@Override
hasPositionInformationback to summary
public boolean hasPositionInformation(Object node)

Implements org.antlr.runtime.tree.PositionTrackingStream.hasPositionInformation.

Doc from org.antlr.runtime.tree.PositionTrackingStream.hasPositionInformation.

Determines if the specified element contains concrete position information.

Parameters
node:Object

the element to check

Returns:boolean

true if element contains concrete position information, otherwise false

Annotations
@Override
isEOFback to summary
public boolean isEOF(Object o)

Implements abstract org.antlr.runtime.misc.LookaheadStream.isEOF.

Annotations
@Override
LAback to summary
public int LA(int i)

Implements org.antlr.runtime.IntStream.LA.

Doc from org.antlr.runtime.IntStream.LA.

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.

Annotations
@Override
nextElementback to summary
public Object nextElement()

Implements abstract org.antlr.runtime.misc.LookaheadStream.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.

Annotations
@Override
popback to summary
public int pop()

Seek back to previous index saved during last push call. Return top of stack (return index).

pushback to summary
public void push(int index)

Make stream jump to a new location, saving old location. Switch back with pop().

removeback to summary
public Object remove()

Overrides org.antlr.runtime.misc.LookaheadStream.remove.

Doc from org.antlr.runtime.misc.LookaheadStream.remove.

Get and remove first element in queue; override FastQueue#remove(); it's the same, just checks for backtracking.

Annotations
@Override
replaceChildrenback to summary
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)

Implements org.antlr.runtime.tree.TreeNodeStream.replaceChildren.

Doc from org.antlr.runtime.tree.TreeNodeStream.replaceChildren.

Replace children of 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.

Annotations
@Override
resetback to summary
public void reset()

Overrides org.antlr.runtime.misc.LookaheadStream.reset.

Implements org.antlr.runtime.tree.TreeNodeStream.reset.

Doc from org.antlr.runtime.tree.TreeNodeStream.reset.

Reset the tree node stream in such a way that it acts like a freshly constructed stream.

Annotations
@Override
setTokenStreamback to summary
public void setTokenStream(TokenStream tokens)
setTreeAdaptorback to summary
public void setTreeAdaptor(TreeAdaptor adaptor)
setUniqueNavigationNodesback to summary
public void setUniqueNavigationNodes(boolean uniqueNavigationNodes)

Implements org.antlr.runtime.tree.TreeNodeStream.setUniqueNavigationNodes.

Doc from org.antlr.runtime.tree.TreeNodeStream.setUniqueNavigationNodes.

As we flatten the tree, we use 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.

Annotations
@Override
toStringback to summary
public String toString(Object start, Object stop)

Implements org.antlr.runtime.tree.TreeNodeStream.toString.

Doc from org.antlr.runtime.tree.TreeNodeStream.toString.

Return the text of all nodes from 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.

Annotations
@Override
toTokenTypeStringback to summary
public String toTokenTypeString()

For debugging; destructive: moves tree iterator to end.