antlr3.tree.CommonTreeAdaptor Class Reference

A TreeAdaptor that works with any Tree implementation. More...

Inheritance diagram for antlr3.tree.CommonTreeAdaptor:

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

Collaboration graph
[legend]

List of all members.

Public Member Functions

def dupNode
 Duplicate a node.
def createWithPayload
 Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload.
def createToken
 Tell me how to create a token for use with imaginary token nodes.
def setTokenBoundaries
 Track start/stop token for subtree root created for a rule.
def getTokenStartIndex
 Get the token start index for this subtree; return -1 if no such index.
def getTokenStopIndex
 Get the token stop index for this subtree; return -1 if no such index.
def getText
def getType
 For tree parsing, I need to know the token type of a node.
def getToken
 What is the Token associated with this node? If you are not using CommonTree, then you must override this in your own adaptor.
def getChild
 Get a child 0.
def getChildCount
 How many children? If 0, then this is a leaf node.
def getParent
 Who is the parent node of this node; if null, implies node is root.
def setParent
 Who is the parent node of this node; if null, implies node is root.
def getChildIndex
 What index is this node in the child list? Range: 0.
def setChildIndex
 What index is this node in the child list? Range: 0.
def replaceChildren
 Replace from start to stop child index of parent with t, which might be a list.


Detailed Description

A TreeAdaptor that works with any Tree implementation.

It provides really just factory methods; all the work is done by BaseTreeAdaptor. If you would like to have different tokens created than ClassicToken objects, you need to override this and then set the parser tree adaptor to use your subclass.

To get your parser to build nodes of a different type, override create(Token).

Definition at line 1469 of file tree.py.


Member Function Documentation

def antlr3.tree.CommonTreeAdaptor.dupNode (   self,
  treeNode 
)

Duplicate a node.

This is part of the factory; override if you want another kind of node to be built.

I could use reflection to prevent having to override this but reflection is slow.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1479 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.createWithPayload (   self,
  payload 
)

Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload.

This is the most common create call.

Override if you want another kind of node to be built.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1487 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.createToken (   self,
  fromToken = None,
  tokenType = None,
  text = None 
)

Tell me how to create a token for use with imaginary token nodes.

For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID).

If you care what the token payload objects' type is, you should override this method and any other createToken variant.

Reimplemented from antlr3.tree.BaseTreeAdaptor.

Definition at line 1501 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.setTokenBoundaries (   self,
  t,
  startToken,
  stopToken 
)

Track start/stop token for subtree root created for a rule.

Only works with Tree nodes. For rules that match nothing, seems like this will yield start=i and stop=i-1 in a nil node. Might be useful info so I'll not force to be i..i.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1516 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getTokenStartIndex (   self,
  t 
)

Get the token start index for this subtree; return -1 if no such index.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1534 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getTokenStopIndex (   self,
  t 
)

Get the token stop index for this subtree; return -1 if no such index.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1540 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getText (   self,
  t 
)

Reimplemented from antlr3.tree.BaseTreeAdaptor.

Definition at line 1546 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getType (   self,
  t 
)

For tree parsing, I need to know the token type of a node.

Reimplemented from antlr3.tree.BaseTreeAdaptor.

Definition at line 1552 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getToken (   self,
  t 
)

What is the Token associated with this node? If you are not using CommonTree, then you must override this in your own adaptor.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1565 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getChild (   self,
  t,
  i 
)

Get a child 0.

.n-1 node

Reimplemented from antlr3.tree.BaseTreeAdaptor.

Definition at line 1573 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getChildCount (   self,
  t 
)

How many children? If 0, then this is a leaf node.

Reimplemented from antlr3.tree.BaseTreeAdaptor.

Definition at line 1579 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getParent (   self,
  t 
)

Who is the parent node of this node; if null, implies node is root.

If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1585 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.setParent (   self,
  t,
  parent 
)

Who is the parent node of this node; if null, implies node is root.

If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1589 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.getChildIndex (   self,
  t 
)

What index is this node in the child list? Range: 0.

.n-1 If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1593 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.setChildIndex (   self,
  t,
  index 
)

What index is this node in the child list? Range: 0.

.n-1 If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.

Reimplemented from antlr3.tree.TreeAdaptor.

Definition at line 1597 of file tree.py.

def antlr3.tree.CommonTreeAdaptor.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.

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.TreeAdaptor.

Definition at line 1601 of file tree.py.


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

Generated on Tue Aug 12 11:42:06 2008 for ANTLR Python API by  doxygen 1.5.5