1
1
class QRegex::P5Regex::Actions is HLL::Actions {
2
2
method TOP ($/ ) {
3
- make qbuildsub($ < nibbler > . ast, : anon(1 ), : addself(1 ));
3
+ make QAST ::CompUnit. new (
4
+ : hll(' P6Regex' ),
5
+ : sc($ * W . sc()),
6
+ : code_ref_blocks($ * W . code_ref_blocks()),
7
+ : compilation_mode(0 ),
8
+ : pre_deserialize($ * W . load_dependency_tasks()),
9
+ : post_deserialize($ * W . fixup_tasks()),
10
+ self . qbuildsub($ < nibbler > . ast, : anon(1 ), : addself(1 ))
11
+ );
4
12
}
5
13
6
14
method nibbler ($/ ) { make $ < alternation > . ast }
@@ -219,7 +227,7 @@ class QRegex::P5Regex::Actions is HLL::Actions {
219
227
: rxtype<subrule >, : subtype<zerowidth >, : negate($ < neg > eq ' !' ), : node($/ ),
220
228
QAST ::Node. new (
221
229
QAST ::SVal. new ( : value(' after' ) ),
222
- qbuildsub(self . flip_ast($ < nibbler > . ast), : anon(1 ), : addself(1 ))
230
+ self . qbuildsub(self . flip_ast($ < nibbler > . ast), : anon(1 ), : addself(1 ))
223
231
));
224
232
}
225
233
else {
@@ -233,7 +241,7 @@ class QRegex::P5Regex::Actions is HLL::Actions {
233
241
: rxtype<subrule >, : subtype<zerowidth >, : node($/ ),
234
242
QAST ::Node. new (
235
243
QAST ::SVal. new ( : value(' before' ) ),
236
- qbuildsub($ < nibbler > . ast, : anon(1 ), : addself(1 ))
244
+ self . qbuildsub($ < nibbler > . ast, : anon(1 ), : addself(1 ))
237
245
));
238
246
}
239
247
else {
@@ -247,7 +255,7 @@ class QRegex::P5Regex::Actions is HLL::Actions {
247
255
: rxtype<subrule >, : subtype<zerowidth >, : negate(1 ), : node($/ ),
248
256
QAST ::Node. new (
249
257
QAST ::SVal. new ( : value(' before' ) ),
250
- qbuildsub($ < nibbler > . ast, : anon(1 ), : addself(1 ))
258
+ self . qbuildsub($ < nibbler > . ast, : anon(1 ), : addself(1 ))
251
259
));
252
260
}
253
261
else {
@@ -308,44 +316,31 @@ class QRegex::P5Regex::Actions is HLL::Actions {
308
316
$ ast ;
309
317
}
310
318
311
- our sub qbuildsub ($ qast , $ block = QAST ::Block. new (), : $ anon , : $ addself ) {
312
- my $ blockid := $ block . cuid;
313
- my $ hashpast := QAST ::Op. new ( : op<hash > );
314
- for capnames($ qast , 0 ) {
315
- if $ _ . key gt ' ' {
316
- $ hashpast . push (QAST ::SVal. new ( : value($ _ . key ) ));
317
- $ hashpast . push (QAST ::IVal. new ( : value(
318
- nqp ::iscclass(pir::const::CCLASS_NUMERIC, $ _ . key , 0 ) + ($ _ . value > 1 ) * 2 ) ));
319
- }
320
- }
321
- my $ initpast := QAST ::Stmts. new ();
322
- if $ addself {
323
- $ initpast . push (QAST ::Var. new ( : name(' self' ), : scope(' local' ), : decl(' param' ) ));
324
- }
325
- my $ capblock := QAST ::BlockMemo. new ( : name($ blockid ~ ' _caps' ), $ hashpast );
326
- $ initpast . push (QAST ::Stmt. new ($ capblock ));
319
+ method qbuildsub ($ qast , $ block = QAST ::Block. new (), : $ anon , : $ addself , * % rest ) {
320
+ my $ code_obj := nqp ::existskey(% rest , ' code_obj' )
321
+ ?? % rest <code_obj >
322
+ !! self . create_regex_code_object($ block );
327
323
328
- my $ nfapast := QRegex::NFA. new . addnode($ qast ). qast;
329
- if $ nfapast {
330
- my $ nfablock := QAST ::BlockMemo. new ( : name($ blockid ~ ' _nfa' ), $ nfapast );
331
- $ initpast . push (QAST ::Stmt. new ($ nfablock ));
324
+ if $ addself {
325
+ $ block . push (QAST ::Var. new ( : name(' self' ), : scope(' local' ), : decl(' param' ) ));
332
326
}
333
-
334
327
unless $ block . symbol(' $¢' ) {
335
- $ initpast . push (QAST ::Var. new (: name<$¢ >, : scope<lexical >, : decl(' var' )));
328
+ $ block . push (QAST ::Var. new (: name<$¢ >, : scope<lexical >, : decl(' var' )));
336
329
$ block . symbol(' $¢' , : scope<lexical >);
337
330
}
338
331
332
+ self . store_regex_caps($ code_obj , $ block , capnames($ qast , 0 ));
333
+ self . store_regex_nfa($ code_obj , $ block , QRegex::NFA. new . addnode($ qast ));
334
+
339
335
$ block <orig_qast > := $ qast ;
340
-
341
336
$ qast := QAST ::Regex. new ( : rxtype<concat >,
342
337
QAST ::Regex. new ( : rxtype<scan > ),
343
338
$ qast ,
344
339
($ anon ??
345
340
QAST ::Regex. new ( : rxtype<pass > ) !!
346
341
QAST ::Regex. new ( : rxtype<pass >, : name(% * RX <name >) )));
347
- $ block . push ($ initpast );
348
342
$ block . push ($ qast );
343
+
349
344
$ block ;
350
345
}
351
346
@@ -414,7 +409,22 @@ class QRegex::P5Regex::Actions is HLL::Actions {
414
409
}
415
410
$ qast
416
411
}
417
-
412
+
413
+ # This is overridden by a compiler that wants to create code objects
414
+ # for regexes. We just use the standard NQP one in standalone mode.
415
+ method create_regex_code_object ($ block ) {
416
+ $ * W . create_code($ block , $ block . name );
417
+ }
418
+
419
+ # Stores the captures info for a regex.
420
+ method store_regex_caps ($ code_obj , $ block , % caps ) {
421
+ $ code_obj . SET_CAPS(% caps );
422
+ }
423
+
424
+ # Override this to store the overall NFA for a regex. (Standalone mode doesn't need
425
+ # it, as it only supports executing individual regexes).
426
+ method store_regex_nfa ($ code_obj , $ block , $ nfa ) {
427
+ }
418
428
419
429
# XXX Below here copied from p6regex; needs review
420
430
@@ -571,8 +581,8 @@ class QRegex::P5Regex::Actions is HLL::Actions {
571
581
}
572
582
elsif $ < nibbler > {
573
583
$ name eq ' after' ??
574
- $ qast [0 ]. push (qbuildsub(self . flip_ast($ < nibbler > [0 ]. ast), : anon(1 ), : addself(1 ))) !!
575
- $ qast [0 ]. push (qbuildsub($ < nibbler > [0 ]. ast, : anon(1 ), : addself(1 )));
584
+ $ qast [0 ]. push (self . qbuildsub(self . flip_ast($ < nibbler > [0 ]. ast), : anon(1 ), : addself(1 ))) !!
585
+ $ qast [0 ]. push (self . qbuildsub($ < nibbler > [0 ]. ast, : anon(1 ), : addself(1 )));
576
586
}
577
587
}
578
588
make $ qast ;
0 commit comments