diff --git a/src/Perl6/Grammar.nqp b/src/Perl6/Grammar.nqp index 7ae49682e3a..9ef2fdf4df5 100644 --- a/src/Perl6/Grammar.nqp +++ b/src/Perl6/Grammar.nqp @@ -1434,8 +1434,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD { if $m 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)"); } diff --git a/src/core/Exception.pm b/src/core/Exception.pm index e627f37615e..103bc80d4c4 100644 --- a/src/core/Exception.pm +++ b/src/core/Exception.pm @@ -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"} }