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 1750 of file tree.py.


Member Function Documentation

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

Definition at line 1752 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 1809 of file tree.py.

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

Definition at line 1815 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 1839 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 1857 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 1878 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 1885 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getCurrentSymbol (   self  ) 

Definition at line 1902 of file tree.py.

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

Look backwards k nodes.

Definition at line 1908 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 1919 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.getSourceName (   self  ) 

Definition at line 1923 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 1927 of file tree.py.

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

Definition at line 1931 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 1935 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.hasUniqueNavigationNodes (   self  ) 

Definition at line 1939 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 1943 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.consume (   self  ) 

Definition at line 1947 of file tree.py.

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

Definition at line 1954 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.mark (   self  ) 

Definition at line 1958 of file tree.py.

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

Definition at line 1967 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.index (   self  ) 

Definition at line 1973 of file tree.py.

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

Definition at line 1977 of file tree.py.

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

Definition at line 1984 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 1996 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 2007 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.reset (   self  ) 

Definition at line 2014 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.size (   self  ) 

Definition at line 2020 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 2029 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.__str__ (   self  ) 

Used for testing, just return the token type stream.

Definition at line 2038 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 2048 of file tree.py.

def antlr3.tree.CommonTreeNodeStream.__iter__ (   self  ) 

iterator interface

Definition at line 2109 of file tree.py.


Member Data Documentation

Definition at line 1768 of file tree.py.

Definition at line 1769 of file tree.py.

Definition at line 1770 of file tree.py.

Definition at line 1780 of file tree.py.

Definition at line 1783 of file tree.py.

Definition at line 1789 of file tree.py.

Definition at line 1792 of file tree.py.

Definition at line 1796 of file tree.py.

Definition at line 1799 of file tree.py.

Definition at line 1802 of file tree.py.


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

Generated on Tue May 20 18:34:07 2008 for ANTLR Python API by  doxygen 1.5.5