Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give decent error for | used outside of arglist.
Before we just called it out as a call to a non-existing prefix:<|>
sub, which was LTA.
  • Loading branch information
jnthn committed Apr 2, 2015
1 parent e88467b commit 10cd401
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Perl6/Grammar.nqp
Expand Up @@ -1007,6 +1007,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*STRICT;
:my $*INVOCANT_OK := 0;
:my $*INVOCANT;
:my $*ARG_FLAT_OK := 0;

# Error related. There are three levels: worry (just a warning), sorry
# (fatal but not immediately so) and panic (immediately deadly). There
Expand Down Expand Up @@ -3378,6 +3379,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token arglist {
:my $*GOAL := 'endargs';
:my $*QSIGIL := '';
:my $*ARG_FLAT_OK := 1;
<.ws>
:dba('argument list')
[
Expand Down Expand Up @@ -3766,11 +3768,12 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*MULTINESS := "";
:my $*OFTYPE;
:my $*VAR;
:my $orig_arg_flat_ok := $*ARG_FLAT_OK;
:dba('term')
[
|| [
| <prefixish>+ [ <term> || {} <.panic("Prefix " ~ $<prefixish>[-1].Str ~ " requires an argument, but no valid term found")> ]
| <term>
| <prefixish>+ [ <.arg_flat_nok> <term> || {} <.panic("Prefix " ~ $<prefixish>[-1].Str ~ " requires an argument, but no valid term found")> ]
| <.arg_flat_nok> <term>
]
|| <!{ $*QSIGIL }> <?before <infixish> {
$/.CURSOR.typed_panic('X::Syntax::InfixInTermPosition', infix => ~$<infixish>); } >
Expand All @@ -3786,7 +3789,11 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
]
|| <!{ $*QSIGIL }> <postfixish>*
]
{ self.check_variable($*VAR) if $*VAR; }
{ self.check_variable($*VAR) if $*VAR; $*ARG_FLAT_OK := $orig_arg_flat_ok; }
}

token arg_flat_nok {
<!{ $*ARG_FLAT_OK := 0 }>
}

sub bracket_ending($matches) {
Expand Down Expand Up @@ -4113,7 +4120,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token prefix:sym<?^> { <sym> <O('%symbolic_unary')> }
token prefix:sym<^^> { <sym> <.dupprefix('^^')> <O('%symbolic_unary')> }
token prefix:sym<^> { <sym> <O('%symbolic_unary')> }
token prefix:sym<|> { <sym> <O('%symbolic_unary')> }
token prefix:sym<|> {
<sym> <O('%symbolic_unary')>
[ <?{ $*ARG_FLAT_OK }> || <.panic: 'Arg-flattening | is only valid in an argument list'> ]
}

token infix:sym<*> { <sym> <O('%multiplicative')> }
token infix:sym</> { <sym> <O('%multiplicative')> }
Expand Down

0 comments on commit 10cd401

Please sign in to comment.