Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #92 from FROGGS/x_backslash
typed exceptions: X::Backslash::UnrecognizedSequence, [...]::NonVariableDollar
  • Loading branch information
moritz committed Nov 28, 2012
2 parents e6e1585 + beea5df commit bfbb051
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Perl6/Grammar.pm
Expand Up @@ -3231,6 +3231,11 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
}

grammar Perl6::QGrammar is HLL::Grammar does STD {

method throw_unrecog_backslash_seq ($sequence) {
$*W.throw(self.MATCH(), <X Backslash UnrecognizedSequence>, :$sequence);
}

proto token escape {*}
proto token backslash {*}

Expand Down Expand Up @@ -3268,7 +3273,7 @@ grammar Perl6::QGrammar is HLL::Grammar does STD {
token escape:sym<$> {
:my $*QSIGIL := '$';
<?before '$'>
[ <EXPR=.LANG('MAIN', 'EXPR', 'y=')> || <.panic: "Non-variable \$ must be backslashed"> ]
[ <EXPR=.LANG('MAIN', 'EXPR', 'y=')> || { $*W.throw($/, 'X::Backslash::NonVariableDollar') } ]
}
}

Expand Down Expand Up @@ -3383,7 +3388,8 @@ grammar Perl6::QGrammar is HLL::Grammar does STD {

role qq does b1 does c1 does s1 does a1 does h1 does f1 {
token stopper { \" }
token backslash:sym<misc> { {} [ (\W) | $<x>=(\w) <.sorry("Unrecognized backslash sequence: '\\" ~ $<x>.Str ~ "'")> ] }
token backslash:sym<unrec> { {} (\w) { self.throw_unrecog_backslash_seq: $/[0].Str } }
token backslash:sym<misc> { \W }

method tweak_q($v) { self.panic("Too late for :q") }
method tweak_qq($v) { self.panic("Too late for :qq") }
Expand Down Expand Up @@ -3443,7 +3449,7 @@ grammar Perl6::QGrammar is HLL::Grammar does STD {
token stopper { <!> }

method truly($bool, $opt) {
self.sorry("Cannot negate $opt adverb") unless $bool;
self.panic("Cannot negate $opt adverb") unless $bool;
self;
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -801,6 +801,15 @@ my class X::Sequence::Deduction is Exception {
method message() { 'Unable to deduce sequence' }
}

my class X::Backslash::UnrecognizedSequence does X::Syntax {
has $.sequence;
method message() { "Unrecognized backslash sequence: '\\$.sequence'" }
}

my class X::Backslash::NonVariableDollar does X::Syntax {
method message() { "Non-variable \$ must be backslashed" }
}

my class X::ControlFlow is Exception {
has $.illegal; # something like 'next'
has $.enclosing; # .... outside a loop
Expand Down

0 comments on commit bfbb051

Please sign in to comment.