Skip to content

Commit e9dbbc5

Browse files
committed
Improve parser internal logic and add builtin tolerant mode support
1 parent d1a45fd commit e9dbbc5

16 files changed

Lines changed: 477 additions & 223 deletions

libs/parser/resources/grammar.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
// The "$offset" variable is an auto-generated
293293
$offset = $ctx->lastProcessedToken->getOffset();
294294

295-
if ($this->literals === false) {
295+
if ($this->features->literals === false) {
296296
throw FeatureNotAllowedException::fromFeature('literal values', $offset);
297297
}
298298
return $children;
@@ -378,7 +378,7 @@
378378
$hint = $attributes = null;
379379

380380
if (\reset($children) instanceof Node\Type\Attribute\AttributeGroupsListNode) {
381-
if ($this->attributes === false) {
381+
if ($this->features->attributes === false) {
382382
throw FeatureNotAllowedException::fromFeature('template argument attributes', $offset);
383383
}
384384

@@ -388,7 +388,7 @@
388388
$type = \array_pop($children);
389389

390390
if (\reset($children) !== false) {
391-
if ($this->hints === false) {
391+
if ($this->features->hints === false) {
392392
throw FeatureNotAllowedException::fromFeature('template argument hints', $offset);
393393
}
394394

@@ -405,7 +405,7 @@
405405
// The "$offset" variable is an auto-generated
406406
$offset = $ctx->lastProcessedToken->getOffset();
407407

408-
if ($this->generics === false) {
408+
if ($this->features->generics === false) {
409409
throw FeatureNotAllowedException::fromFeature('template arguments', $offset);
410410
}
411411

@@ -423,7 +423,7 @@
423423

424424
$name = \array_shift($children);
425425

426-
if ($this->callables === false) {
426+
if ($this->features->callables === false) {
427427
throw FeatureNotAllowedException::fromFeature('callable types', $offset);
428428
}
429429

@@ -444,7 +444,7 @@
444444
$result = \end($children);
445445

446446
if ($children[0] instanceof Node\Type\Attribute\AttributeGroupsListNode) {
447-
if ($this->attributes === false) {
447+
if ($this->features->attributes === false) {
448448
throw FeatureNotAllowedException::fromFeature('callable parameter attributes', $offset);
449449
}
450450

@@ -584,7 +584,7 @@
584584
return new Node\Type\Shape\FieldsListNode();
585585
}
586586

587-
if ($this->shapes === false) {
587+
if ($this->features->shapes === false) {
588588
throw FeatureNotAllowedException::fromFeature('shape fields', $offset);
589589
}
590590

@@ -611,7 +611,7 @@
611611
$result = \end($children);
612612

613613
if ($children[0] instanceof Node\Type\Attribute\AttributeGroupsListNode) {
614-
if ($this->attributes === false) {
614+
if ($this->features->attributes === false) {
615615
throw FeatureNotAllowedException::fromFeature('shape field attributes', $offset);
616616
}
617617

@@ -673,7 +673,7 @@
673673
return $children[0];
674674
}
675675

676-
if ($this->conditional === false) {
676+
if ($this->features->conditions === false) {
677677
throw FeatureNotAllowedException::fromFeature('conditional expressions', $offset);
678678
}
679679

@@ -733,7 +733,7 @@
733733
$offset = $ctx->lastProcessedToken->getOffset();
734734

735735
if (\count($children) === 2) {
736-
if ($this->union === false) {
736+
if ($this->features->unions === false) {
737737
throw FeatureNotAllowedException::fromFeature('union types', $offset);
738738
}
739739

@@ -747,7 +747,7 @@
747747
$offset = $ctx->lastProcessedToken->getOffset();
748748

749749
if (\count($children) === 2) {
750-
if ($this->intersection === false) {
750+
if ($this->features->intersections === false) {
751751
throw FeatureNotAllowedException::fromFeature('intersection types', $offset);
752752
}
753753

@@ -773,15 +773,15 @@
773773
switch (true) {
774774
// In case of list type
775775
case $child === true:
776-
if ($this->list === false) {
776+
if ($this->features->lists === false) {
777777
throw FeatureNotAllowedException::fromFeature('square bracket list types', $offset);
778778
}
779779

780780
$statement = new Node\Type\TypesListNode($statement);
781781
break;
782782
// In case of offset access type
783783
case $child instanceof Node\Type\TypeNode:
784-
if ($this->offsets === false) {
784+
if ($this->features->offsets === false) {
785785
throw FeatureNotAllowedException::fromFeature('type offsets', $offset);
786786
}
787787

libs/parser/resources/grammar.pp2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ LogicalType
6464

6565
UnionType -> {
6666
if (\count($children) === 2) {
67-
if ($this->union === false) {
67+
if ($this->features->unions === false) {
6868
throw FeatureNotAllowedException::fromFeature('union types', $offset);
6969
}
7070

@@ -78,7 +78,7 @@ UnionType -> {
7878

7979
IntersectionType -> {
8080
if (\count($children) === 2) {
81-
if ($this->intersection === false) {
81+
if ($this->features->intersections === false) {
8282
throw FeatureNotAllowedException::fromFeature('intersection types', $offset);
8383
}
8484

@@ -126,15 +126,15 @@ TypesList -> {
126126
switch (true) {
127127
// In case of list type
128128
case $child === true:
129-
if ($this->list === false) {
129+
if ($this->features->lists === false) {
130130
throw FeatureNotAllowedException::fromFeature('square bracket list types', $offset);
131131
}
132132

133133
$statement = new Node\Type\TypesListNode($statement);
134134
break;
135135
// In case of offset access type
136136
case $child instanceof Node\Type\TypeNode:
137-
if ($this->offsets === false) {
137+
if ($this->features->offsets === false) {
138138
throw FeatureNotAllowedException::fromFeature('type offsets', $offset);
139139
}
140140

libs/parser/resources/grammar/callable.pp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
CallableType -> {
33
$name = \array_shift($children);
44

5-
if ($this->callables === false) {
5+
if ($this->features->callables === false) {
66
throw FeatureNotAllowedException::fromFeature('callable types', $offset);
77
}
88

@@ -33,7 +33,7 @@ CallableParameter -> {
3333
$result = \end($children);
3434

3535
if ($children[0] instanceof Node\Type\Attribute\AttributeGroupsListNode) {
36-
if ($this->attributes === false) {
36+
if ($this->features->attributes === false) {
3737
throw FeatureNotAllowedException::fromFeature('callable parameter attributes', $offset);
3838
}
3939

libs/parser/resources/grammar/literals.pp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Literal
66
;
77

88
RawLiteral -> {
9-
if ($this->literals === false) {
9+
if ($this->features->literals === false) {
1010
throw FeatureNotAllowedException::fromFeature('literal values', $offset);
1111
}
1212
return $children;

libs/parser/resources/grammar/shape-fields.pp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ShapeFields -> {
44
return new Node\Type\Shape\FieldsListNode();
55
}
66

7-
if ($this->shapes === false) {
7+
if ($this->features->shapes === false) {
88
throw FeatureNotAllowedException::fromFeature('shape fields', $offset);
99
}
1010

@@ -70,7 +70,7 @@ ShapeField -> {
7070
$result = \end($children);
7171

7272
if ($children[0] instanceof Node\Type\Attribute\AttributeGroupsListNode) {
73-
if ($this->attributes === false) {
73+
if ($this->features->attributes === false) {
7474
throw FeatureNotAllowedException::fromFeature('shape field attributes', $offset);
7575
}
7676

libs/parser/resources/grammar/template-arguments.pp2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
TemplateArguments -> {
3-
if ($this->generics === false) {
3+
if ($this->features->generics === false) {
44
throw FeatureNotAllowedException::fromFeature('template arguments', $offset);
55
}
66

@@ -17,7 +17,7 @@ TemplateArgument -> {
1717
$hint = $attributes = null;
1818

1919
if (\reset($children) instanceof Node\Type\Attribute\AttributeGroupsListNode) {
20-
if ($this->attributes === false) {
20+
if ($this->features->attributes === false) {
2121
throw FeatureNotAllowedException::fromFeature('template argument attributes', $offset);
2222
}
2323

@@ -27,7 +27,7 @@ TemplateArgument -> {
2727
$type = \array_pop($children);
2828

2929
if (\reset($children) !== false) {
30-
if ($this->hints === false) {
30+
if ($this->features->hints === false) {
3131
throw FeatureNotAllowedException::fromFeature('template argument hints', $offset);
3232
}
3333

libs/parser/resources/grammar/ternary.pp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TernaryExpressionOrLogicalType -> {
66
return $children[0];
77
}
88

9-
if ($this->conditional === false) {
9+
if ($this->features->conditions === false) {
1010
throw FeatureNotAllowedException::fromFeature('conditional expressions', $offset);
1111
}
1212

libs/parser/src/Exception/ParseException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
class ParseException extends \LogicException implements ParserExceptionInterface
1111
{
12-
final public const ERROR_CODE_UNEXPECTED_TOKEN = 0x01;
12+
final public const int ERROR_CODE_UNEXPECTED_TOKEN = 0x01;
1313

14-
final public const ERROR_CODE_UNRECOGNIZED_TOKEN = 0x02;
14+
final public const int ERROR_CODE_UNRECOGNIZED_TOKEN = 0x02;
1515

16-
final public const ERROR_CODE_UNEXPECTED_SYNTAX_ERROR = 0x03;
16+
final public const int ERROR_CODE_UNEXPECTED_SYNTAX_ERROR = 0x03;
1717

18-
final public const ERROR_CODE_INTERNAL_ERROR = 0x05;
18+
final public const int ERROR_CODE_INTERNAL_ERROR = 0x05;
1919

20-
final public const ERROR_CODE_SEMANTIC_ERROR_BASE = 0x06;
20+
final public const int ERROR_CODE_SEMANTIC_ERROR_BASE = 0x06;
2121

22-
protected const CODE_LAST = self::ERROR_CODE_SEMANTIC_ERROR_BASE;
22+
protected const int CODE_LAST = self::ERROR_CODE_SEMANTIC_ERROR_BASE;
2323

2424
final public function __construct(string $message, int $code = 0, ?\Throwable $previous = null)
2525
{

0 commit comments

Comments
 (0)