Top Constructors Methods
org.python.antlr

public Class PythonTreeAdaptor

extends CommonTreeAdaptor
Class Inheritance
Known Direct Subclasses
org.python.antlr.AnalyzingParser.AnalyzerTreeAdaptor
Imports
org.antlr.runtime.CommonToken, .RecognitionException, .Token, .TokenStream, org.antlr.runtime.tree.CommonTreeAdaptor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public Object
becomeRoot(Object newRoot, Object oldRoot)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.becomeRoot.

Implements org.antlr.runtime.tree.TreeAdaptor.becomeRoot.

If oldRoot is a nil root, just copy or move the children to newRoot.

public Object
create(Token token)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

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

public Object
create(int tokenType, Token fromToken)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Create a new node derived from a token, with a new token type.

public Object
create(int tokenType, Token fromToken, String text)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Same as create(tokenType,fromToken) except set the text too.

public Object
create(int tokenType, String text)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Create a new node derived from a token, with a new token type.

public Object
deleteChild(Object t, int i)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.deleteChild.

Implements org.antlr.runtime.tree.TreeAdaptor.deleteChild.

Remove ith child and shift children down from right.

public Object
public Object
errorNode(TokenStream input, Token start, Token stop, RecognitionException e)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.errorNode.

Implements org.antlr.runtime.tree.TreeAdaptor.errorNode.

create tree node that holds the start and stop tokens associated with an error.

public Object
public int
public String
public int
getType(Object t)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.getType.

Implements org.antlr.runtime.tree.TreeAdaptor.getType.

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

public boolean
isNil(Object tree)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.isNil.

Implements org.antlr.runtime.tree.TreeAdaptor.isNil.

Is tree considered a nil node used to make lists of child nodes?

public Object
public void
setChild(Object t, int i, Object child)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.setChild.

Implements org.antlr.runtime.tree.TreeAdaptor.setChild.

Set ith child (0..n-1) to t; t must be non-null and non-nil node

public void
setTokenBoundaries(Object t, Token startToken, Token stopToken)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.setTokenBoundaries.

Implements org.antlr.runtime.tree.TreeAdaptor.setTokenBoundaries.

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

Inherited from org.antlr.runtime.tree.CommonTreeAdaptor:
createTokencreateTokengetChildIndexgetParentgetTokengetTokenStartIndexgetTokenStopIndexreplaceChildrensetChildIndexsetParent

Constructor Detail

PythonTreeAdaptorback to summary
public PythonTreeAdaptor()

Method Detail

addChildback to summary
public void addChild(Object t, Object child)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.addChild.

Implements org.antlr.runtime.tree.TreeAdaptor.addChild.

Doc from org.antlr.runtime.tree.BaseTreeAdaptor.addChild.

Add a child to the tree t. If child is a flat tree (a list), make all in list children of t.

Warning

if t has no children, but child does and child isNil then you can decide it is ok to move children to t via t.children = child.children; i.e., without copying the array. Just make sure that this is consistent with have the user will build ASTs.

Annotations
@Override
becomeRootback to summary
public Object becomeRoot(Object newRoot, Object oldRoot)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.becomeRoot.

Implements org.antlr.runtime.tree.TreeAdaptor.becomeRoot.

Doc from org.antlr.runtime.tree.BaseTreeAdaptor.becomeRoot.

If oldRoot is a nil root, just copy or move the children to newRoot. If not a nil root, make oldRoot a child of newRoot. old=^(nil a b c), new=r yields ^(r a b c) old=^(a b c), new=r yields ^(r ^(a b c)) If newRoot is a nil-rooted single child tree, use the single child as the new root node. old=^(nil a b c), new=^(nil r) yields ^(r a b c) old=^(a b c), new=^(nil r) yields ^(r ^(a b c)) If oldRoot was null, it's ok, just return newRoot (even if isNil). old=null, new=r yields r old=null, new=^(nil r) yields ^(nil r) Return newRoot. Throw an exception if newRoot is not a simple node or nil root with a single child node--it must be a root node. If newRoot is ^(nil x) return x as newRoot. Be advised that it's ok for newRoot to point at oldRoot's children; i.e., you don't have to copy the list. We are constructing these nodes so we should have this control for efficiency.

Annotations
@Override
createback to summary
public Object create(Token token)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Doc from org.antlr.runtime.tree.TreeAdaptor.create.

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.

Annotations
@Override
createback to summary
public Object create(int tokenType, Token fromToken)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Doc from org.antlr.runtime.tree.TreeAdaptor.create.

Create a new node derived from a token, with a new token type. This is invoked from an imaginary node ref on right side of a rewrite rule as IMAG[$tokenLabel]. This should invoke createToken(Token).

Annotations
@Override
createback to summary
public Object create(int tokenType, Token fromToken, String text)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Doc from org.antlr.runtime.tree.TreeAdaptor.create.

Same as create(tokenType,fromToken) except set the text too. This is invoked from an imaginary node ref on right side of a rewrite rule as IMAG[$tokenLabel, "IMAG"]. This should invoke createToken(Token).

Annotations
@Override
createback to summary
public Object create(int tokenType, String text)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.create.

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Doc from org.antlr.runtime.tree.TreeAdaptor.create.

Create a new node derived from a token, with a new token type. This is invoked from an imaginary node ref on right side of a rewrite rule as IMAG["IMAG"]. This should invoke createToken(int,String).

Annotations
@Override
deleteChildback to summary
public Object deleteChild(Object t, int i)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.deleteChild.

Implements org.antlr.runtime.tree.TreeAdaptor.deleteChild.

Doc from org.antlr.runtime.tree.TreeAdaptor.deleteChild.

Remove ith child and shift children down from right.

Annotations
@Override
dupNodeback to summary
public Object dupNode(Object t)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.dupNode.

Implements org.antlr.runtime.tree.TreeAdaptor.dupNode.

Doc from org.antlr.runtime.tree.CommonTreeAdaptor.dupNode.

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.

Annotations
@Override
errorNodeback to summary
public Object errorNode(TokenStream input, Token start, Token stop, RecognitionException e)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.errorNode.

Implements org.antlr.runtime.tree.TreeAdaptor.errorNode.

Doc from org.antlr.runtime.tree.BaseTreeAdaptor.errorNode.

create tree node that holds the start and stop tokens associated with an error. If you specify your own kind of tree nodes, you will likely have to override this method. CommonTree returns Token.INVALID_TOKEN_TYPE if no token payload but you might have to set token type for diff node type. You don't have to subclass CommonErrorNode; you will likely need to subclass your own tree node class to avoid class cast exception.

Annotations
@Override
getChildback to summary
public Object getChild(Object t, int i)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.getChild.

Implements org.antlr.runtime.tree.TreeAdaptor.getChild.

Doc from org.antlr.runtime.tree.TreeAdaptor.getChild.

Get a child 0..n-1 node

Annotations
@Override
getChildCountback to summary
public int getChildCount(Object t)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.getChildCount.

Implements org.antlr.runtime.tree.TreeAdaptor.getChildCount.

Doc from org.antlr.runtime.tree.TreeAdaptor.getChildCount.

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

Annotations
@Override
getTextback to summary
public String getText(Object t)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.getText.

Implements org.antlr.runtime.tree.TreeAdaptor.getText.

Annotations
@Override
getTypeback to summary
public int getType(Object t)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.getType.

Implements org.antlr.runtime.tree.TreeAdaptor.getType.

Doc from org.antlr.runtime.tree.TreeAdaptor.getType.

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

Annotations
@Override
isNilback to summary
public boolean isNil(Object tree)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.isNil.

Implements org.antlr.runtime.tree.TreeAdaptor.isNil.

Doc from org.antlr.runtime.tree.TreeAdaptor.isNil.

Is tree considered a nil node used to make lists of child nodes?

Annotations
@Override
rulePostProcessingback to summary
public Object rulePostProcessing(Object root)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.rulePostProcessing.

Implements org.antlr.runtime.tree.TreeAdaptor.rulePostProcessing.

Doc from org.antlr.runtime.tree.BaseTreeAdaptor.rulePostProcessing.

Transform ^(nil x) to x and nil to null

Annotations
@Override
setChildback to summary
public void setChild(Object t, int i, Object child)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.setChild.

Implements org.antlr.runtime.tree.TreeAdaptor.setChild.

Doc from org.antlr.runtime.tree.TreeAdaptor.setChild.

Set ith child (0..n-1) to t; t must be non-null and non-nil node

Annotations
@Override
setTokenBoundariesback to summary
public void setTokenBoundaries(Object t, Token startToken, Token stopToken)

Overrides org.antlr.runtime.tree.CommonTreeAdaptor.setTokenBoundaries.

Implements org.antlr.runtime.tree.TreeAdaptor.setTokenBoundaries.

Doc from org.antlr.runtime.tree.CommonTreeAdaptor.setTokenBoundaries.

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.

Annotations
@Override