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