Package schrodinger :: Package application :: Package desmond :: Package antlr3 :: Module tree :: Class CommonTreeAdaptor
[hide private]
[frames] | no frames]

Class CommonTreeAdaptor

 object --+        
          |        
TreeAdaptor --+    
              |    
BaseTreeAdaptor --+
                  |
                 CommonTreeAdaptor
Known Subclasses:

@brief 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), errorNode(), and to be safe, YourTreeClass.dupNode(). dupNode is called to duplicate nodes during rewrite operations.

Instance Methods [hide private]
 
dupNode(self, treeNode)
Duplicate a node.
 
createWithPayload(self, payload)
Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload.
 
createToken(self, fromToken=None, tokenType=None, text=None)
Tell me how to create a token for use with imaginary token nodes.
 
setTokenBoundaries(self, t, startToken, stopToken)
Track start/stop token for subtree root created for a rule.
 
getTokenStartIndex(self, t)
Get the token start index for this subtree; return -1 if no such index
 
getTokenStopIndex(self, t)
Get the token stop index for this subtree; return -1 if no such index
 
getText(self, t)
 
getType(self, t)
For tree parsing, I need to know the token type of a node
 
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.
 
getChild(self, t, i)
Get a child 0..n-1 node
 
getChildCount(self, t)
How many children? If 0, then this is a leaf node
 
getParent(self, t)
Who is the parent node of this node; if null, implies node is root.
 
setParent(self, t, parent)
Who is the parent node of this node; if null, implies node is root.
 
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.
 
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.
 
replaceChildren(self, parent, startChildIndex, stopChildIndex, t)
Replace from start to stop child index of parent with t, which might be a list.

Inherited from BaseTreeAdaptor: addChild, becomeRoot, createFromToken, createFromType, deleteChild, dupTree, errorNode, getUniqueID, isNil, nil, rulePostProcessing, setChild, setText, setType

Inherited from TreeAdaptor: create

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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.

Overrides: TreeAdaptor.dupNode

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.

Overrides: TreeAdaptor.createWithPayload
(inherited documentation)

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.

Overrides: BaseTreeAdaptor.createToken

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.

Overrides: TreeAdaptor.setTokenBoundaries

getTokenStartIndex(self, t)

 

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

Overrides: TreeAdaptor.getTokenStartIndex
(inherited documentation)

getTokenStopIndex(self, t)

 

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

Overrides: TreeAdaptor.getTokenStopIndex
(inherited documentation)

getText(self, t)

 
Overrides: TreeAdaptor.getText

getType(self, t)

 

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

Overrides: TreeAdaptor.getType
(inherited documentation)

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.

Overrides: TreeAdaptor.getToken

getChild(self, t, i)

 

Get a child 0..n-1 node

Overrides: TreeAdaptor.getChild
(inherited documentation)

getChildCount(self, t)

 

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

Overrides: TreeAdaptor.getChildCount
(inherited documentation)

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.

Overrides: TreeAdaptor.getParent
(inherited documentation)

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.

Overrides: TreeAdaptor.setParent
(inherited documentation)

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.

Overrides: TreeAdaptor.getChildIndex
(inherited documentation)

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.

Overrides: TreeAdaptor.setChildIndex
(inherited documentation)

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.

Overrides: TreeAdaptor.replaceChildren
(inherited documentation)