1 package org.antlr.runtime.tree { 2 /** What does a tree look like? ANTLR has a number of support classes 3 * such as CommonTreeNodeStream that work on these kinds of trees. You 4 * don't have to make your trees implement this interface, but if you do, 5 * you'll be able to use more support code. 6 * 7 * NOTE: When constructing trees, ANTLR can build any kind of tree; it can 8 * even use Token objects as trees if you add a child list to your tokens. 9 * 10 * This is a tree node without any payload; just navigation and factory stuff. 11 */ 12 public interface Tree { 13 14 function getChild(i:int):Tree; 15 16 function get childCount():int; 17 18 // Tree tracks parent and child index now > 3.0 19 20 function get parent():Tree; 21 22 function set parent(t:Tree):void; 23 24 /** Is there is a node above with token type ttype? */ 25 function hasAncestor(ttype:int):Boolean; 26 27 /** Walk upwards and get first ancestor with this token type. */ 28 function getAncestor(ttype:int):Tree; 29 30 /** Return a list of all ancestors of this node. The first node of 31 * list is the root and the last is the parent of this node. 32 */ 33 function get ancestors():Array; 34 35 36 /** This node is what child index? 0..n-1 */ 37 function get childIndex():int; 38 39 function set childIndex(index:int):void; 40 41 /** Set the parent and child index values for all children */ 42 function freshenParentAndChildIndexes():void; 43 44 /** Add t as a child to this node. If t is null, do nothing. If t 45 * is nil, add all children of t to this' children. 46 */ 47 function addChild(t:Tree):void; 48 49 /** Set ith child (0..n-1) to t; t must be non-null and non-nil node */ 50 function setChild(i:int, t:Tree):void; 51 52 function deleteChild(i:int):Object; 53 54 /** Delete children from start to stop and replace with t even if t is 55 * a list (nil-root tree). num of children can increase or decrease. 56 * For huge child lists, inserting children can force walking rest of 57 * children to set their childindex; could be slow. 58 */ 59 function replaceChildren(startChildIndex:int, stopChildIndex:int, t:Object):void; 60 61 /** Indicates the node is a nil node but may still have children, meaning 62 * the tree is a flat list. 63 */ 64 function get isNil():Boolean; 65 66 /** What is the smallest token index (indexing from 0) for this node 67 * and its children? 68 */ 69 function get tokenStartIndex():int; 70 71 function set tokenStartIndex(index:int):void; 72 73 /** What is the largest token index (indexing from 0) for this node 74 * and its children? 75 */ 76 function get tokenStopIndex():int; 77 78 function set tokenStopIndex(index:int):void; 79 80 function dupNode():Tree; 81 82 /** Return a token type; needed for tree parsing */ 83 function get type():int; 84 85 function get text():String; 86 87 /** In case we don't have a token payload, what is the line for errors? */ 88 function get line():int; 89 90 function get charPositionInLine():int; 91 92 function toStringTree():String; 93 94 } 95 96 }