1<?php
2
3declare(strict_types=1);
4
5namespace Antlr\Antlr4\Runtime\Tree;
6
7use Antlr\Antlr4\Runtime\RuleContext;
8
9interface ParseTree extends SyntaxTree
10{
11    /**
12     * @return ParseTree|null
13     */
14    public function getParent() : ?Tree;
15
16    /**
17     * @return ParseTree|null
18     */
19    public function getChild(int $i, ?string $type = null) : ?Tree;
20
21    /**
22     * Set the parent for this node.
23     *
24     * This is not backward compatible as it changes
25     * the interface but no one was able to create custom
26     * nodes anyway so I'm adding as it improves internal
27     * code quality.
28     *
29     * One could argue for a restructuring of
30     * the class/interface hierarchy so that
31     * setParent, addChild are moved up to Tree
32     * but that's a major change. So I'll do the
33     * minimal change, which is to add this method.
34     */
35    public function setParent(RuleContext $parent) : void;
36
37    /**
38     * The {@see ParseTreeVisitor} needs a double dispatch method.
39     */
40    public function accept(ParseTreeVisitor $visitor);
41
42    /**
43     * Return the combined text of all leaf nodes. Does not get any
44     * off-channel tokens (if any) so won't return whitespace and
45     * comments if they are sent to parser on hidden channel.
46     */
47    public function getText() : ?string;
48
49    /**
50     * Specialize toStringTree so that it can print out more information
51     * based upon the parser.
52     *
53     * @param array<string>|null $ruleNames
54     */
55    public function toStringTree(?array $ruleNames = null) : string;
56}
57