Skip to content

Commit

Permalink
QA: Simplify some comma handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Sep 26, 2021
1 parent 649719b commit d309236
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
41 changes: 6 additions & 35 deletions src/main/php/lang/ast/syntax/PHP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/lang/ast/unittest/parse/ErrorsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}
Expand Down

0 comments on commit d309236

Please sign in to comment.