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