Skip to content

Commit

Permalink
Awesomify “malformed loop spec” errors
Browse files Browse the repository at this point in the history
This is a questionable fix for RT #127857.

Makes each parse of a loop construct 0.04 ms slower. So if you have
one hundred 「loop」-s in your code, that's already about four
milliseconds slower.

Also breaks one 6.c-errata test that checks for “loop spec” text.
  • Loading branch information
AlexDaniel committed May 4, 2020
1 parent ee22c2e commit d3c3e53
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Perl6/Grammar.nqp
Expand Up @@ -1202,12 +1202,26 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token statement_control:sym<loop> {
<sym><.kok>
:s''
[ '('
[
<e1=.EXPR>? ';' <e2=.EXPR>? ';' <e3=.EXPR>?
|| <.malformed('loop spec')>
]
')' ]?
[
:my $exprs := 0;
'('
[ <e1=.EXPR>? {$exprs := 1 if $<e1>}
[ ';' <e2=.EXPR>? {$exprs := 2}
[ ';' <e3=.EXPR>? {$exprs := 3}
]? ]? ]? # succeed anyway, this will leave us with a nice cursor
[
|| <?{ $exprs == 3 }> ')'
|| <?before ')'>
[
|| <?{ $exprs == 0 }>
<.malformed("loop spec (expected 3 semicolon-separated expressions)")>
|| <.malformed("loop spec (expected 3 semicolon-separated expressions but got {$exprs})")>
]
|| <?before ‘;’>
<.malformed('loop spec (expected 3 semicolon-separated expressions but got more)')>
|| <.malformed('loop spec')>
]
]?
<block>
}
Expand Down

0 comments on commit d3c3e53

Please sign in to comment.