Skip to content

Commit cab16b3

Browse files
committed
Add support of untyped callable parameters
1 parent 69d3231 commit cab16b3

File tree

2 files changed

+123
-96
lines changed

2 files changed

+123
-96
lines changed

resources/grammar.php

+92-84
Original file line numberDiff line numberDiff line change
@@ -130,79 +130,81 @@
130130
new \Phplrt\Parser\Grammar\Optional(48),
131131
new \Phplrt\Parser\Grammar\Lexeme('T_ANGLE_BRACKET_CLOSE', false),
132132
new \Phplrt\Parser\Grammar\Concatenation([49, 45, 50, 51, 52]),
133-
new \Phplrt\Parser\Grammar\Repetition(136, 1, INF),
133+
new \Phplrt\Parser\Grammar\Repetition(138, 1, INF),
134134
new \Phplrt\Parser\Grammar\Concatenation([16, 59]),
135135
new \Phplrt\Parser\Grammar\Concatenation([59]),
136136
new \Phplrt\Parser\Grammar\Optional(54),
137137
new \Phplrt\Parser\Grammar\Alternation([55, 56]),
138-
new \Phplrt\Parser\Grammar\Concatenation([156]),
138+
new \Phplrt\Parser\Grammar\Concatenation([158]),
139139
new \Phplrt\Parser\Grammar\Concatenation([67, 71, 72]),
140-
new \Phplrt\Parser\Grammar\Concatenation([88, 59]),
140+
new \Phplrt\Parser\Grammar\Concatenation([90, 59]),
141141
new \Phplrt\Parser\Grammar\Lexeme('T_PARENTHESIS_OPEN', false),
142142
new \Phplrt\Parser\Grammar\Optional(60),
143143
new \Phplrt\Parser\Grammar\Lexeme('T_PARENTHESIS_CLOSE', false),
144144
new \Phplrt\Parser\Grammar\Optional(61),
145145
new \Phplrt\Parser\Grammar\Concatenation([2, 62, 63, 64, 65]),
146-
new \Phplrt\Parser\Grammar\Concatenation([74, 73]),
146+
new \Phplrt\Parser\Grammar\Concatenation([74]),
147147
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
148148
new \Phplrt\Parser\Grammar\Concatenation([68, 67]),
149149
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
150150
new \Phplrt\Parser\Grammar\Repetition(69, 0, INF),
151151
new \Phplrt\Parser\Grammar\Optional(70),
152-
new \Phplrt\Parser\Grammar\Concatenation([75, 77]),
153152
new \Phplrt\Parser\Grammar\Optional(54),
154-
new \Phplrt\Parser\Grammar\Concatenation([78, 79]),
153+
new \Phplrt\Parser\Grammar\Concatenation([75, 77]),
154+
new \Phplrt\Parser\Grammar\Alternation([78, 81]),
155155
new \Phplrt\Parser\Grammar\Lexeme('T_ASSIGN', true),
156156
new \Phplrt\Parser\Grammar\Optional(76),
157-
new \Phplrt\Parser\Grammar\Alternation([82, 85]),
157+
new \Phplrt\Parser\Grammar\Concatenation([28]),
158+
new \Phplrt\Parser\Grammar\Alternation([84, 87]),
158159
new \Phplrt\Parser\Grammar\Optional(28),
159-
new \Phplrt\Parser\Grammar\Concatenation([59, 87]),
160+
new \Phplrt\Parser\Grammar\Concatenation([79, 80]),
161+
new \Phplrt\Parser\Grammar\Concatenation([59, 89]),
160162
new \Phplrt\Parser\Grammar\Lexeme('T_ELLIPSIS', true),
161-
new \Phplrt\Parser\Grammar\Concatenation([81, 80]),
163+
new \Phplrt\Parser\Grammar\Concatenation([83, 82]),
162164
new \Phplrt\Parser\Grammar\Lexeme('T_ELLIPSIS', true),
163-
new \Phplrt\Parser\Grammar\Optional(83),
164-
new \Phplrt\Parser\Grammar\Concatenation([80, 84]),
165+
new \Phplrt\Parser\Grammar\Optional(85),
166+
new \Phplrt\Parser\Grammar\Concatenation([82, 86]),
165167
new \Phplrt\Parser\Grammar\Lexeme('T_AMP', true),
166-
new \Phplrt\Parser\Grammar\Optional(86),
168+
new \Phplrt\Parser\Grammar\Optional(88),
167169
new \Phplrt\Parser\Grammar\Lexeme('T_COLON', false),
168-
new \Phplrt\Parser\Grammar\Concatenation([104, 107]),
169-
new \Phplrt\Parser\Grammar\Concatenation([102, 103]),
170+
new \Phplrt\Parser\Grammar\Concatenation([106, 109]),
171+
new \Phplrt\Parser\Grammar\Concatenation([104, 105]),
170172
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
171-
new \Phplrt\Parser\Grammar\Concatenation([91, 90]),
173+
new \Phplrt\Parser\Grammar\Concatenation([93, 92]),
174+
new \Phplrt\Parser\Grammar\Optional(94),
175+
new \Phplrt\Parser\Grammar\Concatenation([91, 95]),
172176
new \Phplrt\Parser\Grammar\Optional(92),
173-
new \Phplrt\Parser\Grammar\Concatenation([89, 93]),
174-
new \Phplrt\Parser\Grammar\Optional(90),
175177
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
176178
new \Phplrt\Parser\Grammar\Lexeme('T_BRACE_OPEN', false),
177-
new \Phplrt\Parser\Grammar\Alternation([94, 95]),
178-
new \Phplrt\Parser\Grammar\Optional(96),
179+
new \Phplrt\Parser\Grammar\Alternation([96, 97]),
180+
new \Phplrt\Parser\Grammar\Optional(98),
179181
new \Phplrt\Parser\Grammar\Lexeme('T_BRACE_CLOSE', false),
180-
new \Phplrt\Parser\Grammar\Concatenation([97, 98, 99, 100]),
182+
new \Phplrt\Parser\Grammar\Concatenation([99, 100, 101, 102]),
181183
new \Phplrt\Parser\Grammar\Lexeme('T_ELLIPSIS', true),
182184
new \Phplrt\Parser\Grammar\Optional(53),
183-
new \Phplrt\Parser\Grammar\Concatenation([110, 111]),
185+
new \Phplrt\Parser\Grammar\Concatenation([112, 113]),
184186
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
185-
new \Phplrt\Parser\Grammar\Concatenation([105, 104]),
186-
new \Phplrt\Parser\Grammar\Repetition(106, 0, INF),
187-
new \Phplrt\Parser\Grammar\Concatenation([112, 115, 116, 114]),
188-
new \Phplrt\Parser\Grammar\Concatenation([114]),
187+
new \Phplrt\Parser\Grammar\Concatenation([107, 106]),
188+
new \Phplrt\Parser\Grammar\Repetition(108, 0, INF),
189+
new \Phplrt\Parser\Grammar\Concatenation([114, 117, 118, 116]),
190+
new \Phplrt\Parser\Grammar\Concatenation([116]),
189191
new \Phplrt\Parser\Grammar\Optional(54),
190-
new \Phplrt\Parser\Grammar\Alternation([108, 109]),
192+
new \Phplrt\Parser\Grammar\Alternation([110, 111]),
191193
new \Phplrt\Parser\Grammar\Alternation([3, 23, 21]),
192194
new \Phplrt\Parser\Grammar\Lexeme('T_QMARK', true),
193195
new \Phplrt\Parser\Grammar\Concatenation([59]),
194-
new \Phplrt\Parser\Grammar\Optional(113),
196+
new \Phplrt\Parser\Grammar\Optional(115),
195197
new \Phplrt\Parser\Grammar\Lexeme('T_COLON', false),
196-
new \Phplrt\Parser\Grammar\Alternation([53, 101]),
197-
new \Phplrt\Parser\Grammar\Optional(117),
198-
new \Phplrt\Parser\Grammar\Concatenation([2, 118]),
199-
new \Phplrt\Parser\Grammar\Concatenation([157]),
200-
new \Phplrt\Parser\Grammar\Optional(123),
201-
new \Phplrt\Parser\Grammar\Concatenation([120, 121]),
202-
new \Phplrt\Parser\Grammar\Concatenation([126, 127, 128, 59, 129, 59]),
203-
new \Phplrt\Parser\Grammar\Concatenation([28, 123]),
204-
new \Phplrt\Parser\Grammar\Alternation([122, 124]),
205-
new \Phplrt\Parser\Grammar\Alternation([130, 131, 132, 133, 134, 135]),
198+
new \Phplrt\Parser\Grammar\Alternation([53, 103]),
199+
new \Phplrt\Parser\Grammar\Optional(119),
200+
new \Phplrt\Parser\Grammar\Concatenation([2, 120]),
201+
new \Phplrt\Parser\Grammar\Concatenation([159]),
202+
new \Phplrt\Parser\Grammar\Optional(125),
203+
new \Phplrt\Parser\Grammar\Concatenation([122, 123]),
204+
new \Phplrt\Parser\Grammar\Concatenation([128, 129, 130, 59, 131, 59]),
205+
new \Phplrt\Parser\Grammar\Concatenation([28, 125]),
206+
new \Phplrt\Parser\Grammar\Alternation([124, 126]),
207+
new \Phplrt\Parser\Grammar\Alternation([132, 133, 134, 135, 136, 137]),
206208
new \Phplrt\Parser\Grammar\Alternation([59, 28]),
207209
new \Phplrt\Parser\Grammar\Lexeme('T_QMARK', false),
208210
new \Phplrt\Parser\Grammar\Lexeme('T_COLON', false),
@@ -212,49 +214,49 @@
212214
new \Phplrt\Parser\Grammar\Lexeme('T_LTE', true),
213215
new \Phplrt\Parser\Grammar\Lexeme('T_ANGLE_BRACKET_OPEN', true),
214216
new \Phplrt\Parser\Grammar\Lexeme('T_ANGLE_BRACKET_CLOSE', true),
215-
new \Phplrt\Parser\Grammar\Concatenation([139, 137, 140, 141]),
216-
new \Phplrt\Parser\Grammar\Concatenation([142, 145]),
217+
new \Phplrt\Parser\Grammar\Concatenation([141, 139, 142, 143]),
218+
new \Phplrt\Parser\Grammar\Concatenation([144, 147]),
217219
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
218220
new \Phplrt\Parser\Grammar\Lexeme('T_ATTR_OPEN', false),
219-
new \Phplrt\Parser\Grammar\Optional(138),
221+
new \Phplrt\Parser\Grammar\Optional(140),
220222
new \Phplrt\Parser\Grammar\Lexeme('T_SQUARE_BRACKET_CLOSE', false),
221-
new \Phplrt\Parser\Grammar\Concatenation([2, 147]),
223+
new \Phplrt\Parser\Grammar\Concatenation([2, 149]),
222224
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
223-
new \Phplrt\Parser\Grammar\Concatenation([143, 142]),
224-
new \Phplrt\Parser\Grammar\Repetition(144, 0, INF),
225-
new \Phplrt\Parser\Grammar\Concatenation([152, 148, 153, 154, 155]),
226-
new \Phplrt\Parser\Grammar\Optional(146),
225+
new \Phplrt\Parser\Grammar\Concatenation([145, 144]),
226+
new \Phplrt\Parser\Grammar\Repetition(146, 0, INF),
227+
new \Phplrt\Parser\Grammar\Concatenation([154, 150, 155, 156, 157]),
228+
new \Phplrt\Parser\Grammar\Optional(148),
227229
new \Phplrt\Parser\Grammar\Concatenation([59]),
228230
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
229-
new \Phplrt\Parser\Grammar\Concatenation([149, 148]),
231+
new \Phplrt\Parser\Grammar\Concatenation([151, 150]),
230232
new \Phplrt\Parser\Grammar\Lexeme('T_COMMA', false),
231233
new \Phplrt\Parser\Grammar\Lexeme('T_PARENTHESIS_OPEN', false),
232-
new \Phplrt\Parser\Grammar\Repetition(150, 0, INF),
233-
new \Phplrt\Parser\Grammar\Optional(151),
234+
new \Phplrt\Parser\Grammar\Repetition(152, 0, INF),
235+
new \Phplrt\Parser\Grammar\Optional(153),
234236
new \Phplrt\Parser\Grammar\Lexeme('T_PARENTHESIS_CLOSE', false),
235-
new \Phplrt\Parser\Grammar\Concatenation([125]),
236-
new \Phplrt\Parser\Grammar\Concatenation([158, 161]),
237-
new \Phplrt\Parser\Grammar\Concatenation([162, 165]),
237+
new \Phplrt\Parser\Grammar\Concatenation([127]),
238+
new \Phplrt\Parser\Grammar\Concatenation([160, 163]),
239+
new \Phplrt\Parser\Grammar\Concatenation([164, 167]),
238240
new \Phplrt\Parser\Grammar\Lexeme('T_OR', false),
239-
new \Phplrt\Parser\Grammar\Concatenation([159, 157]),
240-
new \Phplrt\Parser\Grammar\Optional(160),
241-
new \Phplrt\Parser\Grammar\Concatenation([166]),
241+
new \Phplrt\Parser\Grammar\Concatenation([161, 159]),
242+
new \Phplrt\Parser\Grammar\Optional(162),
243+
new \Phplrt\Parser\Grammar\Concatenation([168]),
242244
new \Phplrt\Parser\Grammar\Lexeme('T_AMP', false),
243-
new \Phplrt\Parser\Grammar\Concatenation([163, 158]),
244-
new \Phplrt\Parser\Grammar\Optional(164),
245-
new \Phplrt\Parser\Grammar\Alternation([169, 167]),
246-
new \Phplrt\Parser\Grammar\Concatenation([170, 172]),
245+
new \Phplrt\Parser\Grammar\Concatenation([165, 160]),
246+
new \Phplrt\Parser\Grammar\Optional(166),
247+
new \Phplrt\Parser\Grammar\Alternation([171, 169]),
248+
new \Phplrt\Parser\Grammar\Concatenation([172, 174]),
247249
new \Phplrt\Parser\Grammar\Lexeme('T_QMARK', true),
248-
new \Phplrt\Parser\Grammar\Concatenation([168, 167]),
249-
new \Phplrt\Parser\Grammar\Alternation([178, 29, 20, 66, 119]),
250-
new \Phplrt\Parser\Grammar\Concatenation([173, 174, 175]),
251-
new \Phplrt\Parser\Grammar\Repetition(171, 0, INF),
250+
new \Phplrt\Parser\Grammar\Concatenation([170, 169]),
251+
new \Phplrt\Parser\Grammar\Alternation([180, 29, 20, 66, 121]),
252+
new \Phplrt\Parser\Grammar\Concatenation([175, 176, 177]),
253+
new \Phplrt\Parser\Grammar\Repetition(173, 0, INF),
252254
new \Phplrt\Parser\Grammar\Lexeme('T_SQUARE_BRACKET_OPEN', true),
253255
new \Phplrt\Parser\Grammar\Optional(59),
254256
new \Phplrt\Parser\Grammar\Lexeme('T_SQUARE_BRACKET_CLOSE', false),
255257
new \Phplrt\Parser\Grammar\Lexeme('T_PARENTHESIS_OPEN', false),
256258
new \Phplrt\Parser\Grammar\Lexeme('T_PARENTHESIS_CLOSE', false),
257-
new \Phplrt\Parser\Grammar\Concatenation([176, 59, 177]),
259+
new \Phplrt\Parser\Grammar\Concatenation([178, 59, 179]),
258260
],
259261
'reducers' => [
260262
0 => static function (\Phplrt\Parser\Context $ctx, $children) {
@@ -434,11 +436,11 @@
434436

435437
return $result;
436438
},
437-
73 => static function (\Phplrt\Parser\Context $ctx, $children) {
439+
74 => static function (\Phplrt\Parser\Context $ctx, $children) {
438440
// The "$offset" variable is an auto-generated
439441
$offset = $ctx->lastProcessedToken->getOffset();
440442

441-
if (!isset($children[1])) {
443+
if (\count($children) === 1) {
442444
return $children[0];
443445
}
444446

@@ -450,16 +452,22 @@
450452
return $children[0];
451453
},
452454
75 => static function (\Phplrt\Parser\Context $ctx, $children) {
453-
if (\count($children) === 1) {
455+
if ($children instanceof Node\Stmt\Callable\CallableParameterNode) {
456+
return $children;
457+
}
454458

459+
if (\count($children) === 1) {
455460
return $children[0];
456461
}
457462

458463
$children[0]->name = $children[1];
459464
return $children[0];
460465
},
461466
78 => static function (\Phplrt\Parser\Context $ctx, $children) {
462-
if (!isset($children[1])) {
467+
return new Node\Stmt\Callable\CallableParameterNode(null, $children[0]);
468+
},
469+
79 => static function (\Phplrt\Parser\Context $ctx, $children) {
470+
if (count($children) === 1) {
463471
return $children[0];
464472
}
465473

@@ -471,7 +479,7 @@
471479
$children[1]->variadic = true;
472480
return $children[1];
473481
},
474-
80 => static function (\Phplrt\Parser\Context $ctx, $children) {
482+
82 => static function (\Phplrt\Parser\Context $ctx, $children) {
475483
$argument = new Node\Stmt\Callable\CallableParameterNode($children[0]);
476484

477485
if (\count($children) !== 1) {
@@ -480,7 +488,7 @@
480488

481489
return $argument;
482490
},
483-
89 => static function (\Phplrt\Parser\Context $ctx, $children) {
491+
91 => static function (\Phplrt\Parser\Context $ctx, $children) {
484492
// The "$offset" variable is an auto-generated
485493
$offset = $ctx->lastProcessedToken->getOffset();
486494

@@ -507,7 +515,7 @@
507515

508516
return new Node\Stmt\Shape\FieldsListNode($children);
509517
},
510-
101 => function (\Phplrt\Parser\Context $ctx, $children) {
518+
103 => function (\Phplrt\Parser\Context $ctx, $children) {
511519
// The "$offset" variable is an auto-generated
512520
$offset = $ctx->lastProcessedToken->getOffset();
513521

@@ -535,7 +543,7 @@
535543

536544
return \array_filter([$parameters, $fields]);
537545
},
538-
104 => function (\Phplrt\Parser\Context $ctx, $children) {
546+
106 => function (\Phplrt\Parser\Context $ctx, $children) {
539547
// The "$offset" variable is an auto-generated
540548
$offset = $ctx->lastProcessedToken->getOffset();
541549

@@ -551,7 +559,7 @@
551559

552560
return $result;
553561
},
554-
108 => static function (\Phplrt\Parser\Context $ctx, $children) {
562+
110 => static function (\Phplrt\Parser\Context $ctx, $children) {
555563
$name = $children[0];
556564
$value = \array_pop($children);
557565

@@ -566,10 +574,10 @@
566574
default => new Node\Stmt\Shape\NamedFieldNode($name, $value, $optional),
567575
};
568576
},
569-
109 => static function (\Phplrt\Parser\Context $ctx, $children) {
577+
111 => static function (\Phplrt\Parser\Context $ctx, $children) {
570578
return new Node\Stmt\Shape\ImplicitFieldNode($children[0]);
571579
},
572-
119 => static function (\Phplrt\Parser\Context $ctx, $children) {
580+
121 => static function (\Phplrt\Parser\Context $ctx, $children) {
573581
$fields = $parameters = null;
574582

575583
// Shape fields
@@ -588,7 +596,7 @@
588596
$fields,
589597
);
590598
},
591-
125 => function (\Phplrt\Parser\Context $ctx, $children) {
599+
127 => function (\Phplrt\Parser\Context $ctx, $children) {
592600
// The "$offset" variable is an auto-generated
593601
$offset = $ctx->lastProcessedToken->getOffset();
594602

@@ -639,21 +647,21 @@
639647
$children[4],
640648
);
641649
},
642-
136 => static function (\Phplrt\Parser\Context $ctx, $children) {
650+
138 => static function (\Phplrt\Parser\Context $ctx, $children) {
643651
return new Node\Stmt\Attribute\AttributeGroupNode($children);
644652
},
645-
142 => static function (\Phplrt\Parser\Context $ctx, $children) {
653+
144 => static function (\Phplrt\Parser\Context $ctx, $children) {
646654
return new Node\Stmt\Attribute\AttributeNode(
647655
$children[0],
648656
);
649657
},
650-
146 => static function (\Phplrt\Parser\Context $ctx, $children) {
658+
148 => static function (\Phplrt\Parser\Context $ctx, $children) {
651659
return new Node\Stmt\Attribute\AttributeArgumentsListNode($children);
652660
},
653-
148 => static function (\Phplrt\Parser\Context $ctx, $children) {
661+
150 => static function (\Phplrt\Parser\Context $ctx, $children) {
654662
return new Node\Stmt\Attribute\AttributeArgumentNode($children[0]);
655663
},
656-
157 => function (\Phplrt\Parser\Context $ctx, $children) {
664+
159 => function (\Phplrt\Parser\Context $ctx, $children) {
657665
// The "$offset" variable is an auto-generated
658666
$offset = $ctx->lastProcessedToken->getOffset();
659667

@@ -667,7 +675,7 @@
667675

668676
return $children;
669677
},
670-
158 => function (\Phplrt\Parser\Context $ctx, $children) {
678+
160 => function (\Phplrt\Parser\Context $ctx, $children) {
671679
// The "$offset" variable is an auto-generated
672680
$offset = $ctx->lastProcessedToken->getOffset();
673681

@@ -681,14 +689,14 @@
681689

682690
return $children;
683691
},
684-
166 => static function (\Phplrt\Parser\Context $ctx, $children) {
692+
168 => static function (\Phplrt\Parser\Context $ctx, $children) {
685693
if (\is_array($children)) {
686694
return new Node\Stmt\NullableTypeNode($children[1]);
687695
}
688696

689697
return $children;
690698
},
691-
167 => function (\Phplrt\Parser\Context $ctx, $children) {
699+
169 => function (\Phplrt\Parser\Context $ctx, $children) {
692700
// The "$offset" variable is an auto-generated
693701
$offset = $ctx->lastProcessedToken->getOffset();
694702

@@ -722,7 +730,7 @@
722730

723731
return $statement;
724732
},
725-
171 => static function (\Phplrt\Parser\Context $ctx, $children) {
733+
173 => static function (\Phplrt\Parser\Context $ctx, $children) {
726734
return $children[1] ?? true;
727735
},
728736
],

0 commit comments

Comments
 (0)