Skip to content

Commit c0ddc72

Browse files
committed
add an indirection for "null pattern not allowed" errors
1 parent bc22f6b commit c0ddc72

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/QRegex/P6Regex/Grammar.nqp

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

47+
# errors are reported through methods, so that subclasses like Rakudo's
48+
# Perl6::RegexGrammar can override them, and throw language-specific
49+
# exceptions
4750
method throw_unrecognized_metachar ($char) {
4851
self.panic('Unrecognized regex metacharacter ' ~ $char ~ ' (must be quoted to match literally)');
4952
}
5053

54+
method throw_null_pattern() {
55+
self.panic('Null regex not allowed');
56+
}
57+
5158
token ws { [ \s+ | '#' \N* ]* }
5259

5360
token normspace { <?before \s | '#' > <.ws> }
@@ -100,22 +107,22 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
100107

101108
token termaltseq {
102109
<termconjseq>
103-
[ '||' [ <termconjseq> || <.panic: 'Null pattern not allowed'> ] ]*
110+
[ '||' [ <termconjseq> || <.throw_null_pattern> ] ]*
104111
}
105112

106113
token termconjseq {
107114
<termalt>
108-
[ '&&' [ <termalt> || <.panic: 'Null pattern not allowed'> ] ]*
115+
[ '&&' [ <termalt> || <.throw_null_pattern> ] ]*
109116
}
110117

111118
token termalt {
112119
<termconj>
113-
[ '|' <![|]> [ <termconj> || <.panic: 'Null pattern not allowed'> ] ]*
120+
[ '|' <![|]> [ <termconj> || <.throw_null_pattern> ] ]*
114121
}
115122

116123
token termconj {
117124
<termish>
118-
[ '&' <![&]> [ <termish> || <.panic: 'Null pattern not allowed'> ] ]*
125+
[ '&' <![&]> [ <termish> || <.throw_null_pattern> ] ]*
119126
}
120127

121128
token termish {

0 commit comments

Comments
 (0)