Lines Matching defs:tree

19      * Print out a whole tree in LISP form. {@see Trees::getNodeText()} is used
25 public static function toStringTree(Tree $tree, ?array $ruleNames = null) : string
27 $string = self::getNodeText($tree, $ruleNames);
30 $childCount = $tree->getChildCount();
39 $child = $tree->getChild($i);
52 public static function getNodeText(Tree $tree, ?array $ruleNames) : string
55 if ($tree instanceof RuleContext) {
56 $ruleIndex = $tree->getRuleContext()->getRuleIndex();
58 $altNumber = $tree->getAltNumber();
67 if ($tree instanceof ErrorNode) {
68 return (string) $tree;
71 if ($tree instanceof TerminalNode && $tree->getSymbol() !== null) {
72 return $tree->getSymbol()->getText() ?? '';
77 $payload = $tree->getPayload();
83 return (string) $tree->getPayload();
91 public static function getChildren(Tree $tree) : array
94 for ($i=0; $i < $tree->getChildCount(); $i++) {
95 $list[] = $tree->getChild($i);
107 public static function getAncestors(Tree $tree) : array
110 $tree = $tree->getParent();
112 while ($tree !== null) {
113 \array_unshift($ancestors, $tree);
115 $tree = $tree->getParent();
124 public static function findAllTokenNodes(ParseTree $tree, int $ttype) : array
126 return self::findAllNodes($tree, $ttype, true);
132 public static function findAllRuleNodes(ParseTree $tree, int $ruleIndex) : array
134 return self::findAllNodes($tree, $ruleIndex, false);
140 public static function findAllNodes(ParseTree $tree, int $index, bool $findTokens) : array
142 return self::findNodesInTree($tree, $index, $findTokens, []);
150 private static function findNodesInTree(ParseTree $tree, int $index, bool $findTokens, array $nodes) : array
153 if ($findTokens && $tree instanceof TerminalNode && $tree->getSymbol()->getType() === $index) {
154 $nodes[] = $tree;
155 } elseif (!$findTokens && $tree instanceof ParserRuleContext && $tree->getRuleIndex() === $index) {
156 $nodes[] = $tree;
160 for ($i = 0; $i < $tree->getChildCount(); $i++) {
161 $child = $tree->getChild($i);
174 public static function descendants(ParseTree $tree) : array
176 $nodes = [$tree];
177 for ($i = 0; $i < $tree->getChildCount(); $i++) {
178 $child = $tree->getChild($i);