| Access | Constructor and Description |
|---|---|
| public |
| PythonTreeAdaptor | back to summary |
|---|---|
| public PythonTreeAdaptor() | |
| addChild | back to summary |
|---|---|
| public void addChild(Object t, Object child) Overrides org. Implements org. Doc from org. 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.
| |
| becomeRoot | back to summary |
|---|---|
| public Object becomeRoot(Object newRoot, Object oldRoot) Overrides org. Implements org. Doc from org. 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.
| |
| create | back to summary |
|---|---|
| public Object create(Token token) Overrides org. Implements org. Doc from org. 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.
| |
| create | back to summary |
|---|---|
| public Object create(int tokenType, Token fromToken) Overrides org. Implements org. Doc from org. 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).
| |
| create | back to summary |
|---|---|
| public Object create(int tokenType, Token fromToken, String text) Overrides org. Implements org. Doc from org. 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).
| |
| create | back to summary |
|---|---|
| public Object create(int tokenType, String text) Overrides org. Implements org. Doc from org. 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).
| |
| deleteChild | back to summary |
|---|---|
| public Object deleteChild(Object t, int i) Overrides org. Implements org. Doc from org. Remove ith child and shift children down from right.
| |
| dupNode | back to summary |
|---|---|
| public Object dupNode(Object t) Overrides org. Implements org. Doc from org. 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.
| |
| errorNode | back to summary |
|---|---|
| public Object errorNode(TokenStream input, Token start, Token stop, RecognitionException e) Overrides org. Implements org. Doc from org. 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.
| |
| getChild | back to summary |
|---|---|
| public Object getChild(Object t, int i) Overrides org. Implements org. Doc from org. Get a child 0..n-1 node
| |
| getChildCount | back to summary |
|---|---|
| public int getChildCount(Object t) Overrides org. Implements org. Doc from org. How many children? If 0, then this is a leaf node
| |
| getText | back to summary |
|---|---|
| public String getText(Object t) Overrides org. Implements org.
| |
| getType | back to summary |
|---|---|
| public int getType(Object t) Overrides org. Implements org. Doc from org. For tree parsing, I need to know the token type of a node
| |
| isNil | back to summary |
|---|---|
| public boolean isNil(Object tree) Overrides org. Implements org. Doc from org. Is tree considered a nil node used to make lists of child nodes?
| |
| rulePostProcessing | back to summary |
|---|---|
| public Object rulePostProcessing(Object root) Overrides org. Implements org. Doc from org. Transform ^(nil x) to x and nil to null
| |
| setChild | back to summary |
|---|---|
| public void setChild(Object t, int i, Object child) Overrides org. Implements org. Doc from org. Set ith child (0..n-1) to t; t must be non-null and non-nil node
| |
| setTokenBoundaries | back to summary |
|---|---|
| public void setTokenBoundaries(Object t, Token startToken, Token stopToken) Overrides org. Implements org. Doc from org. 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.
| |