@@ -137,17 +137,22 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
137
137
}
138
138
139
139
token termish {
140
+ :my $ * SIGOK := 0;
141
+ [
140
142
|| <noun = .quantified_atom >+
141
143
|| <? before <stopper > | <[ &|~ ] > > <.throw_null_pattern >
142
- # || (\W) { self.throw_unrecognized_metachar: ~$/[0] }
144
+ || (\W ) { self . throw_unrecognized_metachar: ~ $/ [0 ] }
145
+ ]
143
146
}
144
147
148
+ method SIGOK () { $ * SIGOK := % * RX <s >; self }
149
+
145
150
token quantified_atom {
146
151
<!rxstopper >
147
- <atom > <sigspace > ** 0 .. 1
152
+ <atom > <sigmaybe >
148
153
[
149
154
[
150
- | <!rxstopper > <quantifier > <quantspace = .sigspace > ** 0 .. 1
155
+ | <!rxstopper > <quantifier > <sigfinal = .sigmaybe >
151
156
| <? before ':' > <backmod > <!alpha >
152
157
]
153
158
[ <separator > ]** 0.. 1
@@ -161,12 +166,23 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
161
166
token atom {
162
167
# :dba('regex atom')
163
168
[
164
- | \w [ \w + ! <? before \w > ]?
169
+ | \w [ \w + ! <? before \w > ]? < .SIGOK >
165
170
| <metachar >
166
171
]
167
172
}
168
173
169
- token sigspace { <?[ \s# ] > <normspace > }
174
+ proto token sigmaybe { <...> }
175
+
176
+ token sigmaybe :sym <normspace > {
177
+ <!{ $ * SIGOK }> <normspace >
178
+ }
179
+
180
+ token sigmaybe :sym <sigwhite > {
181
+ <?{ $ * SIGOK }> <normspace >
182
+ { $ * SIGOK := 0 }
183
+ }
184
+
185
+ token sigmaybe :sym <nosp > { <?[ \S ] > }
170
186
171
187
proto token quantifier { <...> }
172
188
token quantifier :sym <* > { <sym > <backmod > }
@@ -197,22 +213,22 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
197
213
token backmod { ':' ? [ '?' | '!' | <! before ':' > ] }
198
214
199
215
proto token metachar { <...> }
200
- token metachar :sym <[ ] > { '[' <nibbler > ']' }
201
- token metachar :sym <( ) > { '(' <nibbler > ')' }
202
- token metachar :sym <' > { <?[ ' ] > <quote_EXPR : ':q' > }
203
- token metachar :sym <" > { <?[ " ] > <quote_EXPR : ':qq' > }
204
- token metachar :sym <. > { <sym > }
205
- token metachar :sym <^ > { <sym > }
206
- token metachar :sym <^^ > { <sym > }
207
- token metachar :sym <$ > { <sym > }
208
- token metachar :sym <$$ > { <sym > }
216
+ token metachar :sym <[ ] > { '[' <nibbler > ']' < .SIGOK > }
217
+ token metachar :sym <( ) > { '(' <nibbler > ')' < .SIGOK > }
218
+ token metachar :sym <' > { <?[ ' ] > <quote_EXPR : ':q' > < .SIGOK > }
219
+ token metachar :sym <" > { <?[ " ] > <quote_EXPR : ':qq' > < .SIGOK > }
220
+ token metachar :sym <. > { <sym > < .SIGOK > }
221
+ token metachar :sym <^ > { <sym > < .SIGOK > }
222
+ token metachar :sym <^^ > { <sym > < .SIGOK > }
223
+ token metachar :sym <$ > { <sym > < .SIGOK > }
224
+ token metachar :sym <$$ > { <sym > < .SIGOK > }
209
225
token metachar :sym <::: > { <sym > <.panic : '::: not yet implemented' > }
210
226
token metachar :sym <:: > { <sym > <.panic : ':: not yet implemented' > }
211
- token metachar :sym <lwb > { $ < sym > =['<<' | '«' ] }
212
- token metachar :sym <rwb > { $ < sym > =['>>' | '»' ] }
213
- token metachar :sym <from > { '<(' }
214
- token metachar :sym <to > { ')>' }
215
- token metachar :sym <bs > { \\ <backslash > }
227
+ token metachar :sym <lwb > { $ < sym > =['<<' | '«' ] < .SIGOK > }
228
+ token metachar :sym <rwb > { $ < sym > =['>>' | '»' ] < .SIGOK > }
229
+ token metachar :sym <from > { '<(' < .SIGOK > }
230
+ token metachar :sym <to > { ')>' < .SIGOK > }
231
+ token metachar :sym <bs > { \\ <backslash > < .SIGOK > }
216
232
token metachar :sym <mod > { <mod_internal > }
217
233
token metachar :sym <quantifier > {
218
234
<!rxstopper > <quantifier > <.panic : 'Quantifier quantifies nothing' >
@@ -230,8 +246,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
230
246
[ \h * '#= ' \h * $ < key > =[\S + [\h + \S + ]* ] ]** 0.. 1
231
247
}
232
248
token metachar :sym <assert > {
233
- '<' <assertion >
234
- [ '>' || <.panic : 'regex assertion not terminated by angle bracket' > ]
249
+ '<' ~ '>' <assertion > <.SIGOK >
235
250
}
236
251
237
252
token sigil { <[ $@%& ] > }
@@ -335,6 +350,12 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
335
350
')'
336
351
]** 0.. 1
337
352
]
353
+ {
354
+ if ! $ < quote_EXPR > {
355
+ my $ n := $ < n > [0 ] gt ' ' ?? + $ < n > [0 ] !! 1 ;
356
+ % * RX { ~ $ < mod_ident >< sym > } := $ n ;
357
+ }
358
+ }
338
359
}
339
360
340
361
proto token mod_ident { <...> }
0 commit comments