Skip to content

Commit

Permalink
typed exceptions for if()
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Aug 12, 2013
1 parent 2566e75 commit 9bbec9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Perl6/Grammar.nqp
Expand Up @@ -1434,8 +1434,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
if $m<ctx> eq '(' {
$/.CURSOR.'!clear_highwater'();
$/.CURSOR.'!cursor_pos'($m_pos);
$/.CURSOR.sorry("Word '$_' interpreted as '$_" ~ "()' function call; please use whitespace " ~
($needparens ?? 'around the parens' !! 'instead of parens'));
$/.CURSOR.typed_sorry('X::Syntax::IfAsFunction',
word => $_,
:$needparens,
);
$/.CURSOR.'!cursor_pos'($pos);
$/.CURSOR.panic("Unexpected block in infix position (two terms in a row)");
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -754,6 +754,15 @@ my class X::Syntax::UnlessElse does X::Syntax {
method message() { '"unless" does not take "else", please rewrite using "if"' }
}

my class X::Syntax::IfAsFunction does X::Syntax {
has $.word;
has $.needparens;
method message {
"Word '$.word' interpreted as '{$.word}()' function call; please use whitespace "
~ ($.needparens ?? 'around the parens' !! 'instead of parens')
}
}

my class X::Syntax::Malformed::Elsif does X::Syntax {
has $.what = 'else if';
method message() { qq{In Perl 6, please use "elsif' instead of "$.what"} }
Expand Down

0 comments on commit 9bbec9c

Please sign in to comment.