From d309236f306a3d43867b75acfe2413984eb10bcb Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 26 Sep 2021 14:45:24 +0200 Subject: [PATCH] QA: Simplify some comma handling --- src/main/php/lang/ast/syntax/PHP.class.php | 41 +++---------------- .../ast/unittest/parse/ErrorsTest.class.php | 2 +- 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/main/php/lang/ast/syntax/PHP.class.php b/src/main/php/lang/ast/syntax/PHP.class.php index 3308219..4a6594e 100755 --- a/src/main/php/lang/ast/syntax/PHP.class.php +++ b/src/main/php/lang/ast/syntax/PHP.class.php @@ -955,15 +955,9 @@ public function __construct() { $body[$name]= new EnumCase($name, $expr, $meta[DETAIL_ANNOTATIONS] ?? [], $line); $body[$name]->holder= $holder; + } while (',' === $parse->token->value && true | $parse->forward()); - if (',' === $parse->token->value) { - $parse->forward(); - continue; - } else { - $parse->expecting(';', 'case'); - break; - } - } while ($parse->token->value); + $parse->expecting(';', 'case'); }); $this->body('use', function($parse, &$body, $meta, $modifiers, $holder) { @@ -974,13 +968,7 @@ public function __construct() { do { $types[]= $parse->scope->resolve($parse->token->value); $parse->forward(); - if (',' === $parse->token->value) { - $parse->forward(); - continue; - } else { - break; - } - } while ($parse->token->value); + } while (',' === $parse->token->value && true | $parse->forward()); $aliases= []; if ('{' === $parse->token->value) { @@ -1184,14 +1172,7 @@ private function type0($parse, $optional) { $signature= []; if (')' !== $parse->token->value) do { $signature[]= $this->type($parse, false); - if (',' === $parse->token->value) { - $parse->forward(); - } else if (')' === $parse->token->value) { - break; - } else { - $parse->expecting(', or )', 'function type'); - } - } while (true); + } while (',' === $parse->token->value && true | $parse->forward()); $parse->expecting(')', 'type'); $parse->expecting(':', 'type'); return new IsFunction($signature, $this->type($parse, false)); @@ -1283,18 +1264,8 @@ private function attributes($parse, $context) { } else { $attributes[$name]= []; } - - if (',' === $parse->token->value) { - $parse->forward(); - continue; - } else if (']' === $parse->token->value) { - $parse->forward(); - break; - } else { - $parse->expecting(', or ]', $context); - break; - } - } while (true); + } while (',' === $parse->token->value && true | $parse->forward()); + $parse->expecting(']', $context); return $attributes; } diff --git a/src/test/php/lang/ast/unittest/parse/ErrorsTest.class.php b/src/test/php/lang/ast/unittest/parse/ErrorsTest.class.php index 4e5c417..bc9979e 100755 --- a/src/test/php/lang/ast/unittest/parse/ErrorsTest.class.php +++ b/src/test/php/lang/ast/unittest/parse/ErrorsTest.class.php @@ -72,7 +72,7 @@ public function missing_comma_in_interface_parents() { #[Test] public function unclosed_annotation() { $this->assertError( - 'Expected ", or ]", have "(end)" in attributes', + 'Expected "]", have "(end)" in attributes', $this->parse('#[Annotation') ); }