@@ -199,7 +199,15 @@ class NQP::Actions is HLL::Actions {
199
199
# this in the setting as Regex depends on the setting).
200
200
unless % * COMPILING <%?OPTIONS ><setting > eq ' NULL' {
201
201
import_HOW_exports($ SETTING );
202
- $ * W . load_module(' NQPRegex' , $ * GLOBALish );
202
+ if % * COMPILING <%?OPTIONS ><old-regex-lib > {
203
+ $ * W . load_module(' NQPRegex' , $ * GLOBALish );
204
+ }
205
+ unless % * COMPILING <%?OPTIONS ><no-regex-lib > {
206
+ $ * W . load_module(' QRegex' , $ * GLOBALish );
207
+ unless % * COMPILING <%?OPTIONS ><old-regex-lib > {
208
+ $ * W . load_module(' NQPP6QRegex' , $ * GLOBALish );
209
+ }
210
+ }
203
211
}
204
212
}
205
213
self . SET_BLOCK_OUTER_CTX($ * W . cur_lexpad());
@@ -312,7 +320,7 @@ class NQP::Actions is HLL::Actions {
312
320
313
321
sub push_block_handler ($/ , $ block ) {
314
322
my $ BLOCK := $ * W . cur_lexpad();
315
- unless $ BLOCK . handlers() {
323
+ unless $ BLOCK . handlers() {
316
324
$ BLOCK . handlers([]);
317
325
}
318
326
unless $ block . arity {
@@ -347,8 +355,8 @@ class NQP::Actions is HLL::Actions {
347
355
)
348
356
);
349
357
}
350
-
351
- method statement_prefix :sym <BEGIN >($/ ) {
358
+
359
+ method statement_prefix :sym <BEGIN >($/ ) {
352
360
make $ * W . run_begin_block($ < blorst > . ast);
353
361
}
354
362
@@ -576,7 +584,7 @@ class NQP::Actions is HLL::Actions {
576
584
}
577
585
}
578
586
elsif pir:: can ($ how , ' set_default_parent' ) {
579
- my $ default := $ * PKGDECL eq ' grammar' ?? [' Regex ' , ' Cursor ' ] !! [' NQPMu' ];
587
+ my $ default := $ * PKGDECL eq ' grammar' ?? [' NQPCursor ' ] !! [' NQPMu' ];
580
588
$ * W . pkg_add_parent_or_role($ * PACKAGE , " set_default_parent" ,
581
589
$ * W . find_sym($ default ));
582
590
}
@@ -738,7 +746,7 @@ class NQP::Actions is HLL::Actions {
738
746
}
739
747
740
748
# Set up dispatch routine in this scope.
741
- my $ BLOCK := $ * W . cur_lexpad();
749
+ my $ BLOCK := $ * W . cur_lexpad();
742
750
$ cholder := PAST::Op. new ( : pasttype(' list' ) );
743
751
my $ dispatch_setup := PAST::Op. new (
744
752
: pirop(' create_dispatch_and_add_candidates PPP' ),
@@ -763,7 +771,7 @@ class NQP::Actions is HLL::Actions {
763
771
if $ * SCOPE eq ' our' { pir::die(' our-scoped protos not yet implemented' ) }
764
772
my $ cholder := PAST::Op. new ( : pasttype(' list' ) );
765
773
my $ BLOCK := $ * W . cur_lexpad();
766
- $ BLOCK [0 ]. push (PAST::Var. new ( : name($ name ), : isdecl(1 ), : directaccess(1 ),
774
+ $ BLOCK [0 ]. push (PAST::Var. new ( : name($ name ), : isdecl(1 ), : directaccess(1 ),
767
775
: viviself($ past ), : scope(' lexical' ) ) );
768
776
$ BLOCK [0 ]. push (PAST::Op. new (
769
777
: pirop(' set_dispatchees 0PP' ),
@@ -777,7 +785,7 @@ class NQP::Actions is HLL::Actions {
777
785
}
778
786
else {
779
787
my $ BLOCK := $ * W . cur_lexpad();
780
- $ BLOCK [0 ]. push (PAST::Var. new ( : name($ name ), : isdecl(1 ), : directaccess(1 ),
788
+ $ BLOCK [0 ]. push (PAST::Var. new ( : name($ name ), : isdecl(1 ), : directaccess(1 ),
781
789
: viviself($ past ), : scope(' lexical' ) ) );
782
790
$ BLOCK . symbol($ name , : scope(' lexical' ) );
783
791
if $ * SCOPE eq ' our' {
@@ -847,7 +855,7 @@ class NQP::Actions is HLL::Actions {
847
855
# Set name.
848
856
my $ name := ~ $ < private > ~ ~ $ < deflongname > [0 ]. ast;
849
857
$ past . name ($ name );
850
-
858
+
851
859
# Insert it into the method table.
852
860
my $ meta_meth := $ * MULTINESS eq ' multi' ?? ' add_multi_method' !! ' add_method' ;
853
861
my $ is_dispatcher := $ * MULTINESS eq ' proto' ;
@@ -883,7 +891,7 @@ class NQP::Actions is HLL::Actions {
883
891
));
884
892
$ past
885
893
}
886
-
894
+
887
895
sub attach_multi_signature ($ code_obj , $ routine ) {
888
896
my $ types := nqp ::list();
889
897
my $ definednesses := nqp ::list();
@@ -914,7 +922,7 @@ class NQP::Actions is HLL::Actions {
914
922
}
915
923
916
924
method signature ($/ ) {
917
- my $ BLOCK := $ * W . cur_lexpad();
925
+ my $ BLOCK := $ * W . cur_lexpad();
918
926
my $ BLOCKINIT := $ BLOCK [0 ];
919
927
if $ < invocant > {
920
928
my $ inv := $ < invocant > [0 ]. ast;
@@ -1040,7 +1048,6 @@ class NQP::Actions is HLL::Actions {
1040
1048
}
1041
1049
1042
1050
method regex_declarator ($/ , $ key ? ) {
1043
- my @ MODIFIERS := @ Regex ::P6Regex::Actions::MODIFIERS;
1044
1051
my $ name := ~ $ < deflongname > . ast;
1045
1052
my $ past ;
1046
1053
if $ < proto > {
@@ -1057,62 +1064,35 @@ class NQP::Actions is HLL::Actions {
1057
1064
: lexical(0 ),
1058
1065
: node($/ )
1059
1066
),
1060
- PAST::Block. new ( : name(' !PREFIX__' ~ $ name ),
1061
- PAST::Op. new (
1062
- PAST::Var. new ( : name(' self' ), : scope(' parameter' ) ),
1063
- $ name ,
1064
- : name(' !PREFIX__!protoregex' ),
1065
- : pasttype(' callmethod' )
1066
- ),
1067
- : blocktype(' declaration' ),
1068
- : lexical(0 ),
1069
- : node($/ )
1070
- )
1071
1067
);
1072
1068
for @ ($ past ) {
1073
1069
$ * W . pkg_add_method($ * PACKAGE , ' add_method' , $ _ . name (), $ * W . create_code($ _ , $ _ . name (), 0 ));
1074
1070
}
1075
1071
}
1076
- elsif $ key eq ' open' {
1077
- my % h ;
1078
- if $ < sym > eq ' token' { % h <r > := 1 ; }
1079
- if $ < sym > eq ' rule' { % h <r > := 1 ; % h <s > := 1 ; }
1080
- @ MODIFIERS . unshift (% h );
1081
- $ Regex ::P6Regex::Actions::REGEXNAME := $ name ;
1082
- $ * W . cur_lexpad(). symbol(' $¢' , : scope(' lexical' ));
1083
- $ * W . cur_lexpad(). symbol(' $/' , : scope(' lexical' ));
1084
- return 0 ;
1085
- }
1086
1072
else {
1087
- my $ regex :=
1088
- Regex ::P6Regex::Actions::buildsub($ < p6regex > . ast, $ * W . pop_lexpad());
1073
+ my $ block := $ * W . pop_lexpad();
1074
+ $ block [0 ]. unshift (PAST::Var. new (: name<self >, : scope<parameter >));
1075
+ $ block [0 ]. push (
1076
+ PAST::Var. new (: name<self >, : scope<register >, : isdecl(1 ),
1077
+ : viviself(PAST::Var. new ( : name<self >, : scope(' lexical_6model' ) ))));
1078
+ $ block [0 ]. push (PAST::Var. new (: name<$¢ >, : scope<lexical >, : isdecl(1 )));
1079
+ $ block [0 ]. push (PAST::Var. new (: name<$/ >, : scope<lexical >, : isdecl(1 )));
1080
+ $ block . symbol(' $¢' , : scope<lexical >);
1081
+ $ block . symbol(' $/' , : scope<lexical >);
1082
+ my $ regex := QRegex::P6Regex::Actions::buildsub($ < p6regex > . ast, $ block );
1089
1083
$ regex . name ($ name );
1090
- my $ prefix_meth ;
1091
1084
1092
1085
if $ * PKGDECL && pir:: can ($ * PACKAGE . HOW , ' add_method' ) {
1093
1086
# Add the actual method.
1094
1087
$ * W . pkg_add_method($ * PACKAGE , ' add_method' , $ name , $ * W . create_code($ regex , $ name , 0 ));
1095
-
1096
- # Produce the prefixes method and add it.
1097
- my @ prefixes := $ < p6regex > . ast. prefix_list();
1098
- $ prefix_meth := PAST::Block. new (
1099
- : name(' !PREFIX__' ~ $ name ), : blocktype(' method' ),
1100
- PAST::Op. new ( : pasttype(' list' ), | @ prefixes )
1101
- );
1102
- $ * W . pkg_add_method($ * PACKAGE , ' add_method' , $ prefix_meth . name ,
1103
- $ * W . create_code($ prefix_meth , $ prefix_meth . name , 0 ));
1104
1088
}
1105
1089
1106
1090
# In sink context, we don't need the Regex::Regex object.
1107
1091
$ past := PAST::Op. new (
1108
1092
: pasttype<callmethod >, : name<new >,
1109
- lexical_package_lookup([' Regex' , ' Method' ], $/ ),
1110
- $ regex
1111
- );
1112
- $ past <sink > := $ prefix_meth ??
1113
- PAST::Stmts. new ( $ regex , $ prefix_meth ) !!
1114
- $ regex ;
1115
- @ MODIFIERS . shift ;
1093
+ lexical_package_lookup([' NQPRegexMethod' ], $/ ),
1094
+ $ regex );
1095
+ $ past <sink > := $ regex ;
1116
1096
}
1117
1097
make $ past ;
1118
1098
}
@@ -1313,7 +1293,9 @@ class NQP::Actions is HLL::Actions {
1313
1293
method number ($/ ) {
1314
1294
my $ value := $ < dec_number > ?? $ < dec_number > . ast !! $ < integer > . ast;
1315
1295
if ~ $ < sign > eq ' -' { $ value := -$ value ; }
1316
- make PAST::Val. new ( : value($ value ) );
1296
+ make $ < dec_number > ??
1297
+ PAST::Val. new ( : value($ value ) ) !!
1298
+ PAST::Want. new ( PAST::Val. new ( : value($ value ) ), ' Ii' , $ value );
1317
1299
}
1318
1300
1319
1301
method quote :sym <apos >($/ ) { make $ < quote_EXPR > . ast; }
@@ -1327,21 +1309,23 @@ class NQP::Actions is HLL::Actions {
1327
1309
: node($/ ) );
1328
1310
}
1329
1311
1330
- method quote :sym </ /> ($/ , $ key ? ) {
1331
- if $ key eq ' open' {
1332
- $ Regex ::P6Regex::Actions::REGEXNAME := pir::null__P();
1333
- $ * W . cur_lexpad(). symbol(' $¢' , : scope(' lexical' ));
1334
- $ * W . cur_lexpad(). symbol(' $/' , : scope(' lexical' ));
1335
- return 0 ;
1336
- }
1337
- my $ regex :=
1338
- Regex ::P6Regex::Actions::buildsub($ < p6regex > . ast, $ * W . pop_lexpad());
1339
- my $ past :=
1340
- PAST::Op. new (
1341
- : pasttype<callmethod >, : name<new >,
1342
- lexical_package_lookup([' Regex' , ' Regex' ], $/ ),
1343
- $ regex
1344
- );
1312
+ method quote :sym </ /> ($/ ) {
1313
+ my $ block := $ * W . pop_lexpad();
1314
+ $ block [0 ]. push (PAST::Var. new (: name<self >, : scope<parameter >));
1315
+ $ block [0 ]. push (
1316
+ PAST::Var. new (: name<self >, : scope<register >, : isdecl(1 ),
1317
+ : viviself(PAST::Var. new ( : name<self >, : scope(' lexical_6model' ) ))));
1318
+ $ block [0 ]. push (PAST::Var. new (: name<$¢ >, : scope<lexical >, : isdecl(1 )));
1319
+ $ block [0 ]. push (PAST::Var. new (: name<$/ >, : scope<lexical >, : isdecl(1 )));
1320
+ $ block . symbol(' $¢' , : scope<lexical >);
1321
+ $ block . symbol(' $/' , : scope<lexical >);
1322
+
1323
+ my $ regex := QRegex::P6Regex::Actions::buildsub($ < p6regex > . ast, $ block );
1324
+ my $ past := PAST::Op. new (
1325
+ : pasttype<callmethod >, : name<new >,
1326
+ lexical_package_lookup([' NQPRegex' ], $/ ),
1327
+ $ regex );
1328
+
1345
1329
# In sink context, we don't need the Regex::Regex object.
1346
1330
$ past <sink > := $ regex ;
1347
1331
make $ past ;
@@ -1447,38 +1431,38 @@ class NQP::Actions is HLL::Actions {
1447
1431
}
1448
1432
}
1449
1433
1450
- class NQP::RegexActions is Regex ::P6Regex::Actions {
1434
+ class NQP::RegexActions is QRegex ::P6Regex::Actions {
1451
1435
1452
1436
method metachar :sym <:my >($/ ) {
1453
1437
my $ past := $ < statement > . ast;
1454
- make PAST ::Regex. new ( $ past , : pasttype( ' pastnode ' ) ,
1455
- : subtype(' declarative' ), : node($/ ) );
1438
+ make QAST ::Regex. new ( $ past ,
1439
+ : rxtype( ' pastnode ' ), : subtype(' declarative' ), : node($/ ) );
1456
1440
}
1457
1441
1458
1442
method metachar :sym < { }> ($/ ) {
1459
- make PAST ::Regex. new ( $ < codeblock > . ast,
1460
- : pasttype <pastnode >, : node($/ ) );
1443
+ make QAST ::Regex. new ( $ < codeblock > . ast,
1444
+ : rxtype <pastnode >, : node($/ ) );
1461
1445
}
1462
1446
1463
1447
method metachar :sym <nqpvar >($/ ) {
1464
- make PAST ::Regex. new ( ' !INTERPOLATE' , $ < var > . ast,
1465
- : pasttype <subrule >, : subtype<method >, : node($/ ));
1448
+ make QAST ::Regex. new ( PAST::Node . new ( ' !INTERPOLATE' , $ < var > . ast) ,
1449
+ : rxtype <subrule >, : subtype<method >, : node($/ ));
1466
1450
}
1467
1451
1468
1452
method assertion :sym < { }> ($/ ) {
1469
- make PAST ::Regex. new ( ' !INTERPOLATE_REGEX' , $ < codeblock > . ast,
1470
- : pasttype <subrule >, : subtype<method >, : node($/ ));
1453
+ make QAST ::Regex. new ( PAST::Node . new ( ' !INTERPOLATE_REGEX' , $ < codeblock > . ast) ,
1454
+ : rxtype <subrule >, : subtype<method >, : node($/ ));
1471
1455
}
1472
1456
1473
1457
method assertion :sym <? { }> ($/ ) {
1474
- make PAST ::Regex. new ( $ < codeblock > . ast,
1458
+ make QAST ::Regex. new ( $ < codeblock > . ast,
1475
1459
: subtype<zerowidth >, : negate( $ < zw > eq ' !' ),
1476
- : pasttype <pastnode >, : node($/ ) );
1460
+ : rxtype <pastnode >, : node($/ ) );
1477
1461
}
1478
1462
1479
1463
method assertion :sym <var >($/ ) {
1480
- make PAST ::Regex. new ( ' !INTERPOLATE_REGEX' , $ < var > . ast,
1481
- : pasttype <subrule >, : subtype<method >, : node($/ ));
1464
+ make QAST ::Regex. new ( PAST::Node . new ( ' !INTERPOLATE_REGEX' , $ < var > . ast) ,
1465
+ : rxtype <subrule >, : subtype<method >, : node($/ ));
1482
1466
}
1483
1467
1484
1468
method codeblock ($/ ) {
0 commit comments