1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Compiler\Reader; |
11
|
|
|
|
12
|
|
|
use Railt\Compiler\Reader\Analyzer\GrammarAnalyzer; |
13
|
|
|
use Railt\Compiler\Reader\Resolver\PragmaResolver; |
14
|
|
|
use Railt\Compiler\Reader\Resolver\RuleResolver; |
15
|
|
|
use Railt\Compiler\Reader\Resolver\TokenResolver; |
16
|
|
|
use Railt\Lexer\LexerInterface; |
17
|
|
|
use Railt\Parser\ParserInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Result |
21
|
|
|
*/ |
22
|
|
|
class Result |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var Analyzer\Analyzer[] |
26
|
|
|
*/ |
27
|
|
|
private const RULE_ANALYZERS = [ |
28
|
|
|
GrammarAnalyzer::class |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var PragmaResolver |
33
|
|
|
*/ |
34
|
|
|
private $pragmas; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var TokenResolver |
38
|
|
|
*/ |
39
|
|
|
private $tokens; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var RuleResolver |
43
|
|
|
*/ |
44
|
|
|
private $rules; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Result constructor. |
48
|
|
|
* @param PragmaResolver $pragmas |
49
|
|
|
* @param TokenResolver $tokens |
50
|
|
|
* @param RuleResolver $rules |
51
|
|
|
*/ |
52
|
|
|
public function __construct(PragmaResolver $pragmas, TokenResolver $tokens, RuleResolver $rules) |
53
|
|
|
{ |
54
|
|
|
$this->pragmas = $pragmas; |
55
|
|
|
$this->tokens = $tokens; |
56
|
|
|
$this->rules = $rules; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return TokenResolver |
61
|
|
|
*/ |
62
|
|
|
public function tokensResolver(): TokenResolver |
63
|
|
|
{ |
64
|
|
|
return $this->tokens; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return RuleResolver |
69
|
|
|
*/ |
70
|
|
|
public function rulesResolver(): RuleResolver |
71
|
|
|
{ |
72
|
|
|
return $this->rules; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return PragmaResolver |
77
|
|
|
*/ |
78
|
|
|
public function pragmasResolver(): PragmaResolver |
79
|
|
|
{ |
80
|
|
|
return $this->pragmas; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return Runtime |
85
|
|
|
*/ |
86
|
|
|
public function getRuntime(): Runtime |
87
|
|
|
{ |
88
|
|
|
return new Runtime($this); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return ParserInterface |
93
|
|
|
* @throws \InvalidArgumentException |
94
|
|
|
*/ |
95
|
|
|
public function getParser(): ParserInterface |
96
|
|
|
{ |
97
|
|
|
return $this->getRuntime()->getParser(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return LexerInterface |
102
|
|
|
*/ |
103
|
|
|
public function getLexer(): LexerInterface |
104
|
|
|
{ |
105
|
|
|
return $this->getRuntime()->getLexer(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|