Skip to content

Commit

Permalink
Merge pull request #1188 from rakudo/awesome-malformed-loops
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDaniel committed May 4, 2020
2 parents ee22c2e + d3c3e53 commit 1a536ca
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 1a536ca

Please sign in to comment.