@@ -51,6 +51,30 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
51
51
self . panic(' Unrecognized regex metacharacter ' ~ $ char ~ ' (must be quoted to match literally)' );
52
52
}
53
53
54
+ method throw_malformed_range () {
55
+ self . panic(' Malformed range.' );
56
+ }
57
+
58
+ method throw_confused () {
59
+ self . panic(' Confused.' );
60
+ }
61
+
62
+ method throw_unspace ($ char ) {
63
+ self . panic: " No unspace allowed in regex; " ~
64
+ " if you meant to match the literal character," ~
65
+ " please enclose in single quotes ('"
66
+ ~ $ char ~ " ') or use a backslashed form like \\ x"
67
+ ~ nqp :: sprintf (' %02x' , [nqp :: ord ($ char )]);
68
+ }
69
+
70
+ method throw_regex_not_terminated () {
71
+ self . panic(' Regex not terminated.' );
72
+ }
73
+
74
+ method throw_spaces_in_bare_range () {
75
+ self . panic(' Spaces not allowed in bare range.' );
76
+ }
77
+
54
78
method throw_null_pattern () {
55
79
self . panic(' Null regex not allowed' );
56
80
}
@@ -81,7 +105,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
81
105
:my $ handle := '__QREGEX_P6REGEX__' ~ $ cur_handle++ ;
82
106
:my $ * W := QRegex::P6Regex ::World . new(:$ handle );
83
107
<nibbler >
84
- [ $ || <.panic : 'Confused' > ]
108
+ [ $ || <.throw_confused > ]
85
109
}
86
110
87
111
token nibbler {
@@ -104,9 +128,9 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
104
128
<termseq >
105
129
[
106
130
|| <?infixstopper >
107
- || $$ <.panic : "Regex not terminated" >
131
+ || $$ <.throw_regex_not_terminated >
108
132
|| (\W ) { self . throw_unrecognized_metachar: ~ $/ [0 ] }
109
- || <.panic : "Regex not terminated" >
133
+ || <.throw_regex_not_terminated >
110
134
]
111
135
}
112
136
@@ -154,9 +178,9 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
154
178
|| <noun = .quantified_atom >+
155
179
|| <? before <rxstopper > | <[ &|~ ] > > <.throw_null_pattern >
156
180
|| <? before <infixstopper > > <.throw_null_pattern > # XXX Check if unmatched bracket
157
- || $$ <.panic : "Regex not terminated" >
181
+ || $$ <.throw_regex_not_terminated >
158
182
|| (\W ) { self . throw_unrecognized_metachar: ~ $/ [0 ] }
159
- || <.panic : "Regex not terminated" >
183
+ || <.throw_regex_not_terminated >
160
184
]
161
185
}
162
186
@@ -213,15 +237,15 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
213
237
token quantifier :sym <** > {
214
238
<sym > <.normspace >? <backmod > <.normspace >?
215
239
[
216
- | <.integer > \s + '..' <.panic : "Spaces not allowed in bare range" >
240
+ | <.integer > \s + '..' <.throw_spaces_in_bare_range >
217
241
| <min = .integer >
218
242
[ '..'
219
243
[
220
244
| <max = .integer > {
221
245
$/ . CURSOR. panic(" Negative numbers are not allowed as quantifiers" ) if $ < max > . Str < 0 ;
222
246
}
223
247
| $ < max > =['*' ]
224
- | <.panic : "Malformed range" >
248
+ | <.throw_malformed_range >
225
249
]
226
250
]?
227
251
{ $/ . CURSOR. panic(" Negative numbers are not allowed as quantifiers" ) if $ < min > . Str < 0 }
@@ -308,8 +332,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
308
332
token backslash :sym <unrec > { { } (\w ) { self . throw_unrecog_backslash_seq: $/ [0 ]. Str } }
309
333
token backslash :sym <unsp > {
310
334
[\s | '#' ] { }
311
- <.panic : "No unspace allowed in regex; if you meant to match the literal character, please enclose in single quotes ('"
312
- ~ $/ ~ "') or use a backslashed form like \\x" ~ nqp ::sprintf (' %02x' , [nqp :: ord (~ $/ )])>
335
+ <.throw_unspace (~ $/ )>
313
336
}
314
337
token backslash :sym <misc > { \W }
315
338
0 commit comments