Skip to content

Commit

Permalink
Enforce zone constraints in signatures, so we can't end up with requi…
Browse files Browse the repository at this point in the history
…reds after variadics, etc.
  • Loading branch information
jnthn committed Apr 3, 2010
1 parent 3469ffe commit ed9deae
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Perl6/Grammar.pm
Expand Up @@ -768,6 +768,36 @@ token parameter {
<trait>*
<post_constraint>*
<default_value>?

# enforce zone constraints
{
my $kind :=
$<named_param> ?? '*' !!
$<quant> eq '?' ?? '?' !!
$<quant> eq '!' ?? '!' !!
$<quant> ne '' && $<quant> ne '\\' ?? '*' !!
'!';

if $kind eq '!' {
if $*zone eq 'posopt' {
$/.CURSOR.panic("Can't put required parameter after optional parameters");
}
elsif $*zone eq 'var' {
$/.CURSOR.panic("Can't put required parameter after variadic parameters");
}
}
elsif $kind eq '?' {
if $*zone eq 'posreq' {
$*zone := 'posopt';
}
elsif $*zone eq 'var' {
$/.CURSOR.panic("Can't put optional positional parameter after variadic parameters");
}
}
elsif $kind eq '*' {
$*zone := 'var';
}
}
}

token param_var {
Expand Down

0 comments on commit ed9deae

Please sign in to comment.