|
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 Serafim\Properties\Parser; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\Lexer\Factory; |
|
13
|
|
|
use Railt\Lexer\LexerInterface; |
|
14
|
|
|
use Railt\Parser\Driver\Llk; |
|
15
|
|
|
use Railt\Parser\Driver\Stateful; |
|
16
|
|
|
use Railt\Parser\Grammar; |
|
17
|
|
|
use Railt\Parser\ParserInterface; |
|
18
|
|
|
use Railt\Parser\Rule\Alternation; |
|
19
|
|
|
use Railt\Parser\Rule\Concatenation; |
|
20
|
|
|
use Railt\Parser\Rule\Repetition; |
|
21
|
|
|
use Railt\Parser\Rule\Terminal; |
|
22
|
|
|
use Railt\Parser\GrammarInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* --- DO NOT EDIT THIS FILE --- |
|
26
|
|
|
* |
|
27
|
|
|
* Class BaseParser has been auto-generated. |
|
28
|
|
|
* Generated at: 14-10-2018 22:41:34 |
|
29
|
|
|
* |
|
30
|
|
|
* --- DO NOT EDIT THIS FILE --- |
|
31
|
|
|
*/ |
|
32
|
|
|
class BaseParser extends Stateful |
|
33
|
|
|
{ |
|
34
|
|
|
public const T_DOC_DEFINITION = 'T_DOC_DEFINITION'; |
|
35
|
|
|
public const T_VARIABLE = 'T_VARIABLE'; |
|
36
|
|
|
public const T_WORD = 'T_WORD'; |
|
37
|
|
|
public const T_SUFFIX_ARRAY = 'T_SUFFIX_ARRAY'; |
|
38
|
|
|
public const T_NAMESPACE = 'T_NAMESPACE'; |
|
39
|
|
|
public const T_AND = 'T_AND'; |
|
40
|
|
|
public const T_OR = 'T_OR'; |
|
41
|
|
|
public const T_ANGLE_LEFT = 'T_ANGLE_LEFT'; |
|
42
|
|
|
public const T_ANGLE_RIGHT = 'T_ANGLE_RIGHT'; |
|
43
|
|
|
public const T_COMMA = 'T_COMMA'; |
|
44
|
|
|
public const T_WHITESPACE = 'T_WHITESPACE'; |
|
45
|
|
|
public const T_COMMENT = 'T_COMMENT'; |
|
46
|
|
|
public const T_ANY = 'T_ANY'; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Lexical tokens list. |
|
50
|
|
|
* |
|
51
|
|
|
* @var string[] |
|
52
|
|
|
*/ |
|
53
|
|
|
protected const LEXER_TOKENS = [ |
|
54
|
|
|
self::T_DOC_DEFINITION => '@([\\w\\-]+)', |
|
55
|
|
|
self::T_VARIABLE => '\\$([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)', |
|
56
|
|
|
self::T_WORD => '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*', |
|
57
|
|
|
self::T_SUFFIX_ARRAY => '\\[\\]', |
|
58
|
|
|
self::T_NAMESPACE => '\\\\', |
|
59
|
|
|
self::T_AND => '&', |
|
60
|
|
|
self::T_OR => '\\|', |
|
61
|
|
|
self::T_ANGLE_LEFT => '<', |
|
62
|
|
|
self::T_ANGLE_RIGHT => '>', |
|
63
|
|
|
self::T_COMMA => ',', |
|
64
|
|
|
self::T_WHITESPACE => '\\s+', |
|
65
|
|
|
self::T_COMMENT => '\\*', |
|
66
|
|
|
self::T_ANY => '\\S+?', |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* List of skipped tokens. |
|
71
|
|
|
* |
|
72
|
|
|
* @var string[] |
|
73
|
|
|
*/ |
|
74
|
|
|
protected const LEXER_SKIPPED_TOKENS = [ |
|
75
|
|
|
'T_WHITESPACE', |
|
76
|
|
|
'T_COMMENT', |
|
77
|
|
|
'T_ANY', |
|
78
|
|
|
]; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var int |
|
82
|
|
|
*/ |
|
83
|
|
|
protected const LEXER_FLAGS = Factory::LOOKAHEAD; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* List of rule delegates. |
|
87
|
|
|
* |
|
88
|
|
|
* @var string[] |
|
89
|
|
|
*/ |
|
90
|
|
|
protected const PARSER_DELEGATES = [ |
|
91
|
|
|
]; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Parser root rule name. |
|
95
|
|
|
* |
|
96
|
|
|
* @var string |
|
97
|
|
|
*/ |
|
98
|
|
|
protected const PARSER_ROOT_RULE = 'Document'; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return ParserInterface |
|
102
|
|
|
* @throws \InvalidArgumentException |
|
103
|
|
|
* @throws \Railt\Lexer\Exception\BadLexemeException |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function boot(): ParserInterface |
|
106
|
|
|
{ |
|
107
|
|
|
return new Llk($this->bootLexer(), $this->bootGrammar()); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return LexerInterface |
|
112
|
|
|
* @throws \InvalidArgumentException |
|
113
|
|
|
* @throws \Railt\Lexer\Exception\BadLexemeException |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function bootLexer(): LexerInterface |
|
116
|
|
|
{ |
|
117
|
|
|
return Factory::create(static::LEXER_TOKENS, static::LEXER_SKIPPED_TOKENS, static::LEXER_FLAGS); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return GrammarInterface |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function bootGrammar(): GrammarInterface |
|
124
|
|
|
{ |
|
125
|
|
|
return new Grammar([ |
|
126
|
|
|
new Concatenation(0, ['DocBlock'], 'Document'), |
|
127
|
|
|
new Concatenation(1, ['__any'], 'Document'), |
|
128
|
|
|
new Alternation(2, [0, 1], null), |
|
129
|
|
|
(new Repetition('Document', 0, -1, 2, null))->setDefaultId('Document'), |
|
130
|
|
|
new Terminal(4, 'T_WORD', false), |
|
131
|
|
|
new Terminal(5, 'T_DOC_DEFINITION', false), |
|
132
|
|
|
new Terminal(6, 'T_VARIABLE', false), |
|
133
|
|
|
new Terminal(7, 'T_SUFFIX_ARRAY', false), |
|
134
|
|
|
new Terminal(8, 'T_NAMESPACE', false), |
|
135
|
|
|
new Terminal(9, 'T_AND', false), |
|
136
|
|
|
new Terminal(10, 'T_OR', false), |
|
137
|
|
|
new Terminal(11, 'T_ANGLE_LEFT', false), |
|
138
|
|
|
new Terminal(12, 'T_ANGLE_RIGHT', false), |
|
139
|
|
|
new Terminal(13, 'T_COMMA', false), |
|
140
|
|
|
new Alternation('__any', [4, 5, 6, 7, 8, 9, 10, 11, 12, 13], null), |
|
141
|
|
|
new Concatenation(15, ['DocBlockVariable'], null), |
|
142
|
|
|
(new Concatenation('DocBlock', ['DocBlockTitle', 'TypeHint', 15], 'DocBlock'))->setDefaultId('DocBlock'), |
|
143
|
|
|
new Terminal(17, 'T_DOC_DEFINITION', true), |
|
144
|
|
|
(new Concatenation('DocBlockTitle', [17], 'DocBlockTitle'))->setDefaultId('DocBlockTitle'), |
|
145
|
|
|
new Terminal(19, 'T_VARIABLE', true), |
|
146
|
|
|
(new Concatenation('DocBlockVariable', [19], 'DocBlockVariable'))->setDefaultId('DocBlockVariable'), |
|
147
|
|
|
new Concatenation(21, ['__arrayTypeHint'], 'TypeHint'), |
|
148
|
|
|
new Concatenation(22, ['__genericTypeHint'], 'TypeHint'), |
|
149
|
|
|
new Concatenation(23, ['__scalarTypeHint'], 'TypeHint'), |
|
150
|
|
|
new Alternation(24, [21, 22, 23], null), |
|
151
|
|
|
new Repetition(25, 0, 1, '__typeHintContinuation', null), |
|
152
|
|
|
(new Concatenation('TypeHint', [24, 25], null))->setDefaultId('TypeHint'), |
|
153
|
|
|
new Concatenation(27, ['__typeHintDisjunction'], null), |
|
154
|
|
|
new Alternation('__typeHintContinuation', ['__typeHintConjunction', 27], null), |
|
155
|
|
|
new Terminal(29, 'T_OR', false), |
|
156
|
|
|
new Concatenation('__typeHintDisjunction', [29, 'TypeHint'], 'Disjunction'), |
|
157
|
|
|
new Terminal(31, 'T_AND', false), |
|
158
|
|
|
new Concatenation('__typeHintConjunction', [31, 'TypeHint'], 'Conjunction'), |
|
159
|
|
|
new Terminal(33, 'T_SUFFIX_ARRAY', false), |
|
160
|
|
|
new Concatenation('__arrayTypeHint', ['__typeDefinition', 33], 'Array'), |
|
161
|
|
|
new Terminal(35, 'T_ANGLE_LEFT', false), |
|
162
|
|
|
new Repetition(36, 0, 1, '__genericArguments', null), |
|
163
|
|
|
new Terminal(37, 'T_ANGLE_RIGHT', false), |
|
164
|
|
|
new Concatenation('__genericTypeHint', ['__typeDefinition', 35, 36, 37], 'Generic'), |
|
165
|
|
|
new Terminal(39, 'T_COMMA', false), |
|
166
|
|
|
new Concatenation(40, [39, '__scalarTypeHint'], null), |
|
167
|
|
|
new Repetition(41, 0, 1, 40, null), |
|
168
|
|
|
new Concatenation('__genericArguments', ['__scalarTypeHint', 41], 'GenericArguments'), |
|
169
|
|
|
new Concatenation('__scalarTypeHint', ['__typeDefinition'], 'Scalar'), |
|
170
|
|
|
new Terminal(44, 'T_NAMESPACE', false), |
|
171
|
|
|
new Repetition(45, 0, 1, 44, null), |
|
172
|
|
|
new Terminal(46, 'T_WORD', true), |
|
173
|
|
|
new Terminal(47, 'T_NAMESPACE', false), |
|
174
|
|
|
new Terminal(48, 'T_WORD', true), |
|
175
|
|
|
new Concatenation(49, [47, 48], null), |
|
176
|
|
|
new Repetition(50, 0, -1, 49, null), |
|
177
|
|
|
new Concatenation('__typeDefinition', [45, 46, 50], 'Type') |
|
178
|
|
|
], static::PARSER_ROOT_RULE, static::PARSER_DELEGATES); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|