Click or drag to resize

ITreeAdaptor Interface

How to create and navigate trees. Rather than have a separate factory and adaptor, I've merged them. Makes sense to encapsulate.

Namespace:  Stimulsoft.Data.Expressions.Antlr.Runtime.Tree
Assembly:  Stimulsoft.Data (in Stimulsoft.Data.dll) Version: 2019.3.1.0
Syntax
public interface ITreeAdaptor

The ITreeAdaptor type exposes the following members.

Methods
  NameDescription
Public methodAddChild
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. Do nothing if t or child is null.
Public methodBecomeRoot(Object, Object)
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.
Public methodBecomeRoot(IToken, Object)
Create a node for newRoot make it the root of oldRoot. 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.
Public methodCreate(IToken)
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.
Public methodCreate(Int32, IToken)
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].
Public methodCreate(Int32, String)
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"].
Public methodCreate(IToken, String)
Same as create(fromToken) except set the text too. This is invoked when the text terminal option is set, as in IMAG<text='IMAG'>.
Public methodCreate(Int32, IToken, String)
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"].
Public methodDeleteChild
Remove ith child and shift children down from right.
Public methodDupNode(Object)
Duplicate a single tree node.
Public methodDupNode(Int32, Object)
Public methodDupNode(Object, String)
Public methodDupNode(Int32, Object, String)
Public methodDupTree
Duplicate tree recursively, using dupNode() for each node
Public methodErrorNode
Return a tree node representing an error. This node records the tokens consumed during error recovery. The start token indicates the input symbol at which the error was detected. The stop token indicates the last symbol consumed during recovery.
Public methodGetChild
Get a child 0..n-1 node
Public methodGetChildCount
How many children? If 0, then this is a leaf node
Public methodGetChildIndex
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.
Public methodGetParent
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.
Public methodGetText
Public methodGetToken
Return the token object from which this node was created. Currently used only for printing an error message. The error display routine in BaseRecognizer needs to display where the input the error occurred. If your tree of limitation does not store information that can lead you to the token, you can create a token filled with the appropriate information and pass that back. See BaseRecognizer.getErrorMessage().
Public methodGetTokenStartIndex
Get the token start index for this subtree; return -1 if no such index
Public methodGetTokenStopIndex
Get the token stop index for this subtree; return -1 if no such index
Public methodGetType
For tree parsing, I need to know the token type of a node
Public methodGetUniqueID
For identifying trees.
Public methodIsNil
Is tree considered a nil node used to make lists of child nodes?
Public methodNil
Return a nil node (an empty but non-null node) that can hold a list of element as the children. If you want a flat tree (a list) use "t=adaptor.nil(); t.addChild(x); t.addChild(y);"
Public methodReplaceChildren
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.
Public methodRulePostProcessing
Given the root of the subtree created for this rule, post process it to do any simplifications or whatever you want. A required behavior is to convert ^(nil singleSubtree) to singleSubtree as the setting of start/stop indexes relies on a single non-nil root for non-flat trees.
Public methodSetChild
Set ith child (0..n-1) to t; t must be non-null and non-nil node
Public methodSetChildIndex
Public methodSetParent
Public methodSetText
Node constructors can set the text of a node
Public methodSetTokenBoundaries
Where are the bounds in the input token stream for this node and all children? Each rule that creates AST nodes will call this method right before returning. Flat trees (i.e., lists) will still usually have a nil root node just to hold the children list. That node would contain the start/stop indexes then.
Public methodSetType
Node constructors can set the type of a node
Top
Remarks
This takes the place of the tree construction code generated in the generated code in 2.x and the ASTFactory. I do not need to know the type of a tree at all so they are all generic Objects. This may increase the amount of typecasting needed. :(
See Also