-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTerminalNodeImpl.php
88 lines (69 loc) · 1.67 KB
/
TerminalNodeImpl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace Antlr\Antlr4\Runtime\Tree;
use Antlr\Antlr4\Runtime\Interval;
use Antlr\Antlr4\Runtime\RuleContext;
use Antlr\Antlr4\Runtime\Token;
class TerminalNodeImpl implements TerminalNode
{
public Token $symbol;
public ?ParseTree $parent = null;
public function __construct(Token $symbol)
{
$this->symbol = $symbol;
}
public function getChild(int $i, ?string $type = null): ?Tree
{
return null;
}
public function getSymbol(): Token
{
return $this->symbol;
}
/**
* @return ParseTree|null
*/
public function getParent(): ?Tree
{
return $this->parent;
}
public function setParent(RuleContext $parent): void
{
$this->parent = $parent;
}
public function getPayload(): Token
{
return $this->symbol;
}
public function getSourceInterval(): Interval
{
$tokenIndex = $this->symbol->getTokenIndex();
return new Interval($tokenIndex, $tokenIndex);
}
public function getChildCount(): int
{
return 0;
}
public function accept(ParseTreeVisitor $visitor): mixed
{
return $visitor->visitTerminal($this);
}
public function getText(): ?string
{
return $this->symbol->getText();
}
/**
* @param array<string>|null $ruleNames
*/
public function toStringTree(?array $ruleNames = null): string
{
return (string) $this;
}
public function __toString(): string
{
if ($this->symbol->getType() === Token::EOF) {
return '<EOF>';
}
return $this->symbol->getText() ?? '';
}
}