antlr3.tree.CommonTreeNodeStream Class Reference

A buffered stream of tree nodes. More...

Inheritance diagram for antlr3.tree.CommonTreeNodeStream:

Inheritance graph
[legend]
Collaboration diagram for antlr3.tree.CommonTreeNodeStream:

Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def fillBuffer
 Walk tree with depth-first-search and fill nodes buffer.
def getNodeIndex
 What is the stream index for node? 0.
def addNavigationNode
 As we flatten the tree, we use UP, DOWN nodes to represent the tree structure.
def get
 Get a tree node at an absolute index i; 0.
def LT
 Get tree node at current input pointer + i ahead where i=1 is next node.
def getCurrentSymbol
def LB
 Look backwards k nodes.
def getTreeSource
 Where is this stream pulling nodes from? This is not the name, but the object that provides node objects.
def getSourceName
def getTokenStream
 If the tree associated with this stream was created from a TokenStream, you can specify it here.
def setTokenStream
def getTreeAdaptor
 What adaptor can tell me how to interpret/navigate nodes and trees.
def hasUniqueNavigationNodes
def setUniqueNavigationNodes
 As we flatten the tree, we use UP, DOWN nodes to represent the tree structure.
def consume
def LA
def mark
def release
def index
def rewind
def seek
def push
 Make stream jump to a new location, saving old location.
def pop
 Seek back to previous index saved during last push() call.
def reset
def size
def replaceChildren
 Replace from start to stop child index of parent with t, which might be a list.
def __str__
 Used for testing, just return the token type stream.
def toString
 Return the text of all nodes from start to stop, inclusive.
def __iter__
 iterator interface

Public Attributes

 down
 up
 eof
 nodes
 root
 adaptor
 uniqueNavigationNodes
 p
 lastMarker
 calls

Private Member Functions

def _fillBuffer


Detailed Description

A buffered stream of tree nodes.

Nodes can be from a tree of ANY kind.

This node stream sucks all nodes out of the tree specified in the constructor during construction and makes pointers into the tree using an array of Object pointers. The stream necessarily includes pointers to DOWN and UP and EOF nodes.

This stream knows how to mark/release for backtracking.

This stream is most suitable for tree interpreters that need to jump around a lot or for tree parsers requiring speed (at cost of memory). There is some duplicated functionality here with UnBufferedTreeNodeStream but just in bookkeeping, not tree walking etc...

See also:
UnBufferedTreeNodeStream

Definition at line 1849 of file tree.py.


Member Function Documentation

def antlr3.tree.CommonTreeNodeStream.__init__ (   self,
  args 
)

Definition at line 1851 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.fillBuffer (   self  ) 

Walk tree with depth-first-search and fill nodes buffer.

Don't do DOWN, UP nodes if its a list (t is isNil).

Definition at line 1945 of file tree.py.

def antlr3.tree.CommonTreeNodeStream._fillBuffer (   self,
  t 
) [private]

Definition at line 1951 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getNodeIndex (   self,
  node 
)

What is the stream index for node? 0.

.n-1 Return -1 if node not found.

Definition at line 1975 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.addNavigationNode (   self,
  ttype 
)

As we flatten the tree, we use UP, DOWN nodes to represent the tree structure.

When debugging we need unique nodes so instantiate new ones when uniqueNavigationNodes is true.

Definition at line 1993 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.get (   self,
  i 
)

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.

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2014 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.LT (   self,
  k 
)

Get tree node at current input pointer + i ahead where i=1 is next node.

i<0 indicates nodes in the past. So LT(-1) is previous node, but implementations are not required to provide results for k < -1. LT(0) is undefined. For i>=n, return null. Return null for LT(0) and any index that results in an absolute address that is negative.

This is analogus to the LT() method of the TokenStream, but this returns a tree node instead of a token. Makes code gen identical for both parser and tree grammars. :)

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2021 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getCurrentSymbol (   self  ) 

Definition at line 2037 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.LB (   self,
  k 
)

Look backwards k nodes.

Definition at line 2043 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getTreeSource (   self  ) 

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

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2054 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getSourceName (   self  ) 

Definition at line 2058 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getTokenStream (   self  ) 

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.

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2062 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.setTokenStream (   self,
  tokens 
)

Definition at line 2066 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getTreeAdaptor (   self  ) 

What adaptor can tell me how to interpret/navigate nodes and trees.

E.g., get text of a node.

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2070 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.hasUniqueNavigationNodes (   self  ) 

Definition at line 2074 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.setUniqueNavigationNodes (   self,
  uniqueNavigationNodes 
)

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

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2078 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.consume (   self  ) 

Definition at line 2082 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.LA (   self,
  i 
)

Definition at line 2089 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.mark (   self  ) 

Definition at line 2093 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.release (   self,
  marker = None 
)

Definition at line 2102 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.index (   self  ) 

Definition at line 2108 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.rewind (   self,
  marker = None 
)

Definition at line 2112 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.seek (   self,
  index 
)

Definition at line 2119 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.push (   self,
  index 
)

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

Switch back with pop().

Definition at line 2131 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.pop (   self  ) 

Seek back to previous index saved during last push() call.

Return top of stack (return index).

Definition at line 2142 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.reset (   self  ) 

Definition at line 2149 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.size (   self  ) 

Definition at line 2155 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.replaceChildren (   self,
  parent,
  startChildIndex,
  stopChildIndex,
  t 
)

Replace from start to stop child index of parent 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.

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2164 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.__str__ (   self  ) 

Used for testing, just return the token type stream.

Definition at line 2173 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.toString (   self,
  start,
  stop 
)

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.

Reimplemented from antlr3.tree.TreeNodeStream.

Definition at line 2183 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.__iter__ (   self  ) 

iterator interface

Definition at line 2244 of file tree.py.


Member Data Documentation

Definition at line 1891 of file tree.py.

Definition at line 1896 of file tree.py.

Definition at line 1901 of file tree.py.

Definition at line 1914 of file tree.py.

Definition at line 1919 of file tree.py.

Definition at line 1925 of file tree.py.

Definition at line 1928 of file tree.py.

Definition at line 1932 of file tree.py.

Definition at line 1935 of file tree.py.

Definition at line 1938 of file tree.py.


The documentation for this class was generated from the following file:

Generated on Mon Nov 29 17:24:29 2010 for ANTLR Python API by  doxygen 1.5.5