xref: /plugin/combo/vendor/antlr/antlr4-php-runtime/src/Tree/Tree.php (revision 37748cd8654635afbeca80942126742f0f4cc346)
1*37748cd8SNickeau<?php
2*37748cd8SNickeau
3*37748cd8SNickeaudeclare(strict_types=1);
4*37748cd8SNickeau
5*37748cd8SNickeaunamespace Antlr\Antlr4\Runtime\Tree;
6*37748cd8SNickeau
7*37748cd8SNickeau/**
8*37748cd8SNickeau * The basic notion of a tree has a parent, a payload, and a list of children.
9*37748cd8SNickeau * It is the most abstract interface for all the trees used by ANTLR.
10*37748cd8SNickeau */
11*37748cd8SNickeauinterface Tree
12*37748cd8SNickeau{
13*37748cd8SNickeau    /**
14*37748cd8SNickeau     * The parent of this node. If the return value is null, then this
15*37748cd8SNickeau     * node is the root of the tree.
16*37748cd8SNickeau     */
17*37748cd8SNickeau    public function getParent() : ?Tree;
18*37748cd8SNickeau
19*37748cd8SNickeau    /**
20*37748cd8SNickeau     * This method returns whatever object represents the data at this note. For
21*37748cd8SNickeau     * example, for parse trees, the payload can be a {@see Token} representing
22*37748cd8SNickeau     * a leaf node or a {@see RuleContext} object representing a rule
23*37748cd8SNickeau     * invocation. For abstract syntax trees (ASTs), this is a {@see Token}
24*37748cd8SNickeau     * object.
25*37748cd8SNickeau     */
26*37748cd8SNickeau    public function getPayload();
27*37748cd8SNickeau
28*37748cd8SNickeau    /**
29*37748cd8SNickeau     * If there are children, get the `i`th value indexed from 0.
30*37748cd8SNickeau     */
31*37748cd8SNickeau    public function getChild(int $i, ?string $type = null) : ?Tree;
32*37748cd8SNickeau
33*37748cd8SNickeau    /**
34*37748cd8SNickeau     * How many children are there? If there is none, then this node represents a leaf node.
35*37748cd8SNickeau     */
36*37748cd8SNickeau    public function getChildCount() : int;
37*37748cd8SNickeau
38*37748cd8SNickeau    /**
39*37748cd8SNickeau     * Print out a whole tree, not just a node, in LISP format
40*37748cd8SNickeau     * `(root child1 .. childN)`. Print just a node if this is a leaf.
41*37748cd8SNickeau     *
42*37748cd8SNickeau     * @param array<string>|null $ruleNames
43*37748cd8SNickeau     */
44*37748cd8SNickeau    public function toStringTree(?array $ruleNames = null) : string;
45*37748cd8SNickeau}
46