Lines Matching defs:Tree
1 """ @package antlr3.tree
2 @brief ANTLR3 runtime package, tree module
4 This module contains all support classes for AST construction and tree parsers.
54 # tree related exceptions
94 # basic Tree and TreeAdaptor interfaces
98 class Tree(object):
100 @brief Abstract baseclass for tree nodes.
102 What does a tree look like? ANTLR has a number of support classes
107 NOTE: When constructing trees, ANTLR can build any kind of tree; it can
110 This is a tree node without any payload; just navigation and factory stuff.
123 """Tree tracks parent and child index now > 3.0"""
128 """Tree tracks parent and child index now > 3.0"""
192 a list (nil-root tree). num of children can increase or decrease.
203 the tree is a flat list.
240 """Return a token type; needed for tree parsing."""
272 @brief Abstract baseclass for tree adaptors.
277 This takes the place of the tree construction code generated in the
280 I do not need to know the type of a tree at all so they are all
288 Create a tree node from Token object; for CommonTree type trees,
299 """Duplicate a single tree node.
306 def dupTree(self, tree):
307 """Duplicate tree recursively, using dupNode() for each node"""
315 a list of element as the children. If you want a flat tree (a list)
324 Return a tree node representing an error. This node records the
334 This only makes sense during token parsing, not tree parsing.
335 Tree parsing should happen only when parsing and tree construction
342 def isNil(self, tree):
343 """Is tree considered a nil node used to make lists of child nodes?"""
350 Add a child to the tree t. If child is a flat tree (a list), make all
369 If newRoot is a nil-rooted single child tree, use the single
405 This method is executed after all rule tree construction and right
454 """For tree parsing, I need to know the token type of a node"""
480 tree of limitation does not store information that can
546 If your node type doesn't handle this, it's ok but the tree rewrites
547 in tree parsers need this functionality.
556 If your node type doesn't handle this, it's ok but the tree rewrites
557 in tree parsers need this functionality.
566 If your node type doesn't handle this, it's ok but the tree rewrites
567 in tree parsers need this functionality.
576 If your node type doesn't handle this, it's ok but the tree rewrites
577 in tree parsers need this functionality.
589 If parent is null, don't do anything; must be at root of overall tree.
660 # base implementation of Tree and TreeAdaptor
662 # Tree
671 class BaseTree(Tree):
673 @brief A generic tree implementation with no payload.
677 instead of the child-sibling approach in v2. A flat tree (a list) is
693 Tree.__init__(self)
796 a list (nil-root tree). num of children can increase or decrease.
922 """Print out a whole tree not just a node"""
953 """Override to say how a node (not a tree) should look as text"""
961 @brief A TreeAdaptor that works with any Tree implementation.
974 create tree node that holds the start and stop tokens associated
977 If you specify your own kind of tree nodes, you will likely have to
983 subclass your own tree node class to avoid class cast exception.
989 def isNil(self, tree):
990 return tree.isNil()
996 tree (not just Tree interface). It invokes the adaptor routines
997 not the tree node routines to do the construction.
1007 # same index in new tree
1020 def addChild(self, tree, child):
1022 Add a child to the tree t. If child is a flat tree (a list), make all
1033 if tree is not None and child is not None:
1034 tree.addChild(child)
1045 If newRoot is a nil-rooted single child tree, use the single
1082 # TODO: make tree run time exceptions hierarchy
1086 # is a flat list (i.e., nil-rooted tree). All children of oldRoot
1138 raise RuntimeError("don't know enough about Tree node")
1146 raise RuntimeError("don't know enough about Tree node")
1185 # common tree implementation
1187 # Tree
1200 """@brief A tree node that is wrapper for a Token object.
1203 while building tree rewrite stuff, it became clear that computing
1205 spend the space in every tree node. If you don't want these extra
1438 elif isinstance(self.start, Tree):
1442 # people should subclass if they alter the tree type so this
1475 @brief A TreeAdaptor that works with any Tree implementation.
1480 objects, you need to override this and then set the parser tree adaptor to
1527 Only works with Tree nodes. For rules that match nothing,
1638 """@brief A stream of tree nodes
1640 It accessing nodes from a tree of some kind.
1648 """Get a tree node at an absolute index i; 0..n-1.
1658 Get tree node at current input pointer + i ahead where i=1 is next node.
1666 returns a tree node instead of a token. Makes code gen identical
1667 for both parser and tree grammars. :)
1684 If the tree associated with this stream was created from a TokenStream,
1685 you can specify it here. Used to do rule $text attribute in tree
1686 parser. Optional unless you use tree parser rule text attribute
1704 As we flatten the tree, we use UP, DOWN nodes to represent
1705 the tree structure. When debugging we need unique nodes
1706 so we have to instantiate new ones. When doing normal tree
1716 Reset the tree node stream in such a way that it acts like
1735 tree parser)
1741 tree and might need to know you are monkeying with the underlying
1742 tree. Also, it might be able to modify the node stream to avoid
1745 If parent is null, don't do anything; must be at root of overall tree.
1753 """@brief A buffered stream of tree nodes.
1755 Nodes can be from a tree of ANY kind.
1757 This node stream sucks all nodes out of the tree specified in
1759 the tree using an array of Object pointers. The stream necessarily
1764 This stream is most suitable for tree interpreters that need to
1765 jump around a lot or for tree parsers requiring speed (at cost of memory).
1767 but just in bookkeeping, not tree walking etc...
1777 tree = args[0]
1786 tree = args[1]
1799 tree = parent.root
1826 # The complete mapping from stream index to tree node.
1839 # Pull nodes from which tree?
1840 self.root = tree
1842 # IF this tree (root) was created from a token stream, track it.
1845 # What tree adaptor was used to build these trees
1867 """Walk tree with depth-first-search and fill nodes buffer.
1912 As we flatten the tree, we use UP, DOWN nodes to represent
1913 the tree structure. When debugging we need unique nodes
2085 # TREE REWRITE INTERFACE
2127 # if it's a tree, use start/stop index from start node
2176 # tree parser
2181 """@brief Baseclass for generated tree parsers.
2183 A parser for a stream of tree nodes. "tree grammars" result in a subclass
2235 Context means sequence of nodes towards root of tree. For example,
2313 Match '.' in tree parser has special meaning. Skip node or
2314 entire tree if node has children. If children, scan until
2346 from tree parser errors inline...
2356 the input tree not the user.
2369 Tree parsers parse nodes they usually have a token object as
2395 # tree visitor
2400 """Do a depth first walk of a tree, applying pre() and post() actions
2411 """Visit every node in tree t and trigger an action for each node
2443 # tree iterator
2449 Return a node stream from a doubly-linked tree whose nodes
2452 Emit navigation nodes (DOWN, UP, and EOF) to let show tree structure.
2455 def __init__(self, tree, adaptor=None):
2459 self.root = tree
2463 self.tree = tree
2477 self.tree = self.root
2492 if self.tree is None:
2495 if self.adaptor.getChildCount(self.tree) > 0:
2499 return self.adaptor.getParent(self.tree) is not None
2509 if self.adaptor.getChildCount(self.tree) == 0:
2510 # single node tree (special)
2512 return self.tree
2514 return self.tree
2521 if self.tree is None:
2525 if self.adaptor.getChildCount(self.tree) > 0:
2526 self.tree = self.adaptor.getChild(self.tree, 0)
2528 self.nodes.append(self.tree)
2531 # if no children, look for next sibling of tree or ancestor
2532 parent = self.adaptor.getParent(self.tree)
2535 and self.adaptor.getChildIndex(self.tree)+1 >= self.adaptor.getChildCount(parent)):
2538 self.tree = parent
2539 parent = self.adaptor.getParent(self.tree)
2543 self.tree = None # back at root? nothing left then
2549 nextSiblingIndex = self.adaptor.getChildIndex(self.tree) + 1
2550 self.tree = self.adaptor.getChild(parent, nextSiblingIndex)
2551 self.nodes.append(self.tree) # add to queue, might have UP nodes in there
2573 @see org.antlr.runtime.tree.RewriteRuleSubtreeStream
2574 @see org.antlr.runtime.tree.RewriteRuleTokenStream
2669 a tree node or subtree. Deal with the optimization of single-
2701 the element is for a tree root; then it must be a node dup.
2746 # Don't convert to a tree unless they explicitly call nextTree.
2747 # This way we can do hetero tree nodes in rewrite.
2771 tree root node. Also prevents us from duplicating recently-added
2775 Referencing a rule result twice is ok; dup entire tree as
2780 and super.next() doesn't know which to call: dup node or dup tree.
2807 Queues up nodes matched on left side of -> in a tree parser. This is
2828 the start property is a tree nodes not Token object
2829 when you are parsing trees. To be generic the tree node types
2835 self.tree = None
2843 return self.tree