Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add typed exceptions for conditional operator
  • Loading branch information
usev6 committed Mar 30, 2015
1 parent 64fe6c5 commit 9aecf6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Perl6/Grammar.nqp
Expand Up @@ -4212,12 +4212,12 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<.ws>
<EXPR('j=')>
[ '!!'
|| <?before '::'<-[=]>> <.panic: "Please use !! rather than ::">
|| <?before ':' <-[=]>> <.panic: "Please use !! rather than :">
|| <infixish> {} <.panic("Precedence of $<infixish> is too loose to use inside ?? !!; please parenthesize")>
|| <?{ ~$<EXPR> ~~ / '!!' / }> <.panic("Your !! was gobbled by the expression in the middle; please parenthesize")>
|| <?before \N*? [\n\N*?]? '!!'> <.sorry("Bogus code found before the !!")> <.panic("Confused")>
|| <.sorry("Found ?? but no !!")> <.panic("Confused")>
|| <?before '::' <-[=]>> { self.typed_panic: "X::Syntax::ConditionalOperator::SecondPartInvalid", second-part => "::" }
|| <?before ':' <-[=]>> { self.typed_panic: "X::Syntax::ConditionalOperator::SecondPartInvalid", second-part => ":" }
|| <infixish> { self.typed_panic: "X::Syntax::ConditionalOperator::PrecedenceTooLoose", operator => ~$<infixish> }
|| <?{ ~$<EXPR> ~~ / '!!' / }> { self.typed_panic: "X::Syntax::ConditionalOperator::SecondPartGobbled" }
|| <?before \N*? [\n\N*?]? '!!'> { self.typed_panic: "X::Syntax::Confused", reason => "Confused: Bogus code found before the !! of conditional operator" }
|| { self.typed_panic: "X::Syntax::Confused", reason => "Confused: Found ?? but no !!" }
]
<O('%conditional, :reducecheck<ternary>, :pasttype<if>')>
}
Expand Down
14 changes: 14 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -943,6 +943,20 @@ my class X::Syntax::BlockGobbled does X::Syntax {
method message() { "{ $.what ?? 'Function ' ~ $.what !! 'Expression' } needs parens to avoid gobbling block" };
}

my class X::Syntax::ConditionalOperator::PrecedenceTooLoose does X::Syntax {
has $.operator;
method message() { "Precedence of $.operator is too loose to use inside ?? !!; please parenthesize" }
}

my class X::Syntax::ConditionalOperator::SecondPartGobbled does X::Syntax {
method message() { "Your !! was gobbled by the expression in the middle; please parenthesize" }
}

my class X::Syntax::ConditionalOperator::SecondPartInvalid does X::Syntax {
has $.second-part;
method message() { "Please use !! rather than $.second-part" }
}

my class X::Syntax::Perl5Var does X::Syntax {
has $.name;
my %m =
Expand Down

0 comments on commit 9aecf6e

Please sign in to comment.