Skip to content

Commit bc22f6b

Browse files
committed
throwing warning from method to support typed exceptions
1 parent d0f9fec commit bc22f6b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/QRegex/P6Regex/Grammar.nqp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
4444
~ ~$when ~ ' please use ' ~ ~$new);
4545
}
4646

47+
method throw_unrecognized_metachar ($char) {
48+
self.panic('Unrecognized regex metacharacter ' ~ $char ~ ' (must be quoted to match literally)');
49+
}
50+
4751
token ws { [ \s+ | '#' \N* ]* }
4852

4953
token normspace { <?before \s | '#' > <.ws> }
@@ -78,7 +82,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
7882
[
7983
|| <?infixstopper>
8084
|| $$ <.panic: "Regex not terminated">
81-
|| (\W) { $/.CURSOR.panic("Unrecognized regex metacharacter " ~ $/[0].Str ~ " (must be quoted to match literally)") }
85+
|| (\W) { self.throw_unrecognized_metachar: ~$/[0] }
8286
|| <.panic: "Regex not terminated">
8387
]
8488
}
@@ -116,10 +120,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
116120

117121
token termish {
118122
|| <noun=.quantified_atom>+
119-
|| (\W) {
120-
my $char := ~$/[0];
121-
$/.CURSOR.panic("Unrecognized regex metacharacter $char (must be quoted to match literally)")
122-
}
123+
|| (\W) { self.throw_unrecognized_metachar: ~$/[0] }
123124
}
124125

125126
token quantified_atom {

0 commit comments

Comments
 (0)