@@ -35,6 +35,7 @@ role NQPCursorRole is export {
35
35
has $ ! cstack ;
36
36
has $ ! regexsub ;
37
37
has $ ! restart ;
38
+ has $ ! actions ;
38
39
39
40
method orig () { nqp ::getattr($ ! shared , ParseShared, ' $!orig' ) }
40
41
method target () { nqp ::getattr_s($ ! shared , ParseShared, ' $!target' ) }
@@ -48,6 +49,14 @@ role NQPCursorRole is export {
48
49
$ ! regexsub := NQPMu;
49
50
}
50
51
52
+ # method AOK($actions, $where) {
53
+ # my $got := nqp::getattr(self,NQPCursor,'$!actions');
54
+ # if nqp::objectid(nqp::getattr(self,NQPCursor,'$!actions')) != nqp::objectid($actions) {
55
+ # nqp::printfh(nqp::getstderr(), "actions bad in $where (expected " ~ $actions.HOW.name($actions) ~ " but got " ~ $got.HOW.name($got) ~ ")\n");
56
+ # }
57
+ # self;
58
+ # }
59
+
51
60
method ! APPEND_TO_ORIG ($ value ) {
52
61
my $ orig := nqp ::getattr($ ! shared , ParseShared, ' $!orig' );
53
62
$ orig := $ orig ~ $ value ;
@@ -115,7 +124,7 @@ role NQPCursorRole is export {
115
124
$ caps ;
116
125
}
117
126
118
- method ! cursor_init ($ orig , : $ p = 0 , : $ c , : $ shared , * % ignore ) {
127
+ method ! cursor_init ($ orig , : $ p = 0 , : $ c , : $ shared , : $ actions , * % ignore ) {
119
128
my $ new := self . CREATE();
120
129
unless $ shared {
121
130
$ shared := nqp ::create(ParseShared);
@@ -127,6 +136,7 @@ role NQPCursorRole is export {
127
136
nqp ::bindattr($ shared , ParseShared, ' %!marks' , nqp ::hash());
128
137
}
129
138
nqp ::bindattr($ new , $ ? CLASS , ' $!shared' , $ shared );
139
+ nqp ::bindattr($ new , $ ? CLASS , ' $!actions' , $ actions );
130
140
if nqp :: defined ($ c ) {
131
141
nqp ::bindattr_i($ new , $ ? CLASS , ' $!from' , -1 );
132
142
nqp ::bindattr_i($ new , $ ? CLASS , ' $!pos' , $ c );
@@ -150,6 +160,7 @@ role NQPCursorRole is export {
150
160
# Uncomment following to log cursor creation.
151
161
# $!shared.log_cc(nqp::getcodename($sub));
152
162
nqp ::bindattr($ new , $ ? CLASS , ' $!shared' , $ ! shared );
163
+ nqp ::bindattr($ new , $ ? CLASS , ' $!actions' , $ ! actions ) if nqp ::isconcrete(self );
153
164
nqp ::bindattr($ new , $ ? CLASS , ' $!regexsub' , nqp ::ifnull(nqp ::getcodeobj($ sub ), $ sub ));
154
165
if nqp :: defined ($ ! restart ) {
155
166
nqp ::bindattr_i($ new , $ ? CLASS , ' $!pos' , $ ! pos );
@@ -182,6 +193,7 @@ role NQPCursorRole is export {
182
193
# Uncomment following to log cursor creation.
183
194
# $!shared.log_cc(nqp::getcodename($sub));
184
195
nqp ::bindattr($ new , $ ? CLASS , ' $!shared' , $ ! shared );
196
+ nqp ::bindattr($ new , $ ? CLASS , ' $!actions' , $ ! actions ) if nqp ::isconcrete(self );
185
197
nqp ::bindattr($ new , $ ? CLASS , ' $!regexsub' , nqp ::ifnull(nqp ::getcodeobj($ sub ), $ sub ));
186
198
if nqp :: defined ($ ! restart ) {
187
199
nqp ::bindattr_i($ new , $ ? CLASS , ' $!pos' , $ ! pos );
@@ -205,6 +217,7 @@ role NQPCursorRole is export {
205
217
# Uncomment following to log cursor creation.
206
218
# $!shared.log_cc(nqp::getcodename($sub));
207
219
nqp ::bindattr($ new , $ ? CLASS , ' $!shared' , $ ! shared );
220
+ nqp ::bindattr($ new , $ ? CLASS , ' $!actions' , $ ! actions ) if nqp ::isconcrete(self );
208
221
nqp ::bindattr($ new , $ ? CLASS , ' $!regexsub' , nqp ::ifnull(nqp ::getcodeobj($ sub ), $ sub ));
209
222
if nqp :: defined ($ ! restart ) {
210
223
nqp ::die(" !cursor_start_cur cannot restart a cursor" );
@@ -222,6 +235,7 @@ role NQPCursorRole is export {
222
235
method ! cursor_start_subcapture ($ from ) {
223
236
my $ new := nqp ::create(self );
224
237
nqp ::bindattr($ new , $ ? CLASS , ' $!shared' , $ ! shared );
238
+ nqp ::bindattr($ new , $ ? CLASS , ' $!actions' , $ ! actions ) if nqp ::isconcrete(self );
225
239
nqp ::bindattr_i($ new , $ ? CLASS , ' $!from' , $ from );
226
240
nqp ::bindattr_i($ new , $ ? CLASS , ' $!pos' , -3 );
227
241
$ new ;
@@ -312,14 +326,14 @@ role NQPCursorRole is export {
312
326
}
313
327
314
328
method ! reduce (str $ name ) {
315
- my $ actions := nqp ::getlexdyn( ' $*ACTIONS ' ) ;
329
+ my $ actions := $ ! actions ;
316
330
nqp ::findmethod($ actions , $ name )($ actions , self . MATCH)
317
331
if ! nqp ::isnull($ actions ) && nqp :: can ($ actions , $ name );
318
332
self ;
319
333
}
320
334
321
335
method ! reduce_with_match (str $ name , str $ key , $ match ) {
322
- my $ actions := nqp ::getlexdyn( ' $*ACTIONS ' ) ;
336
+ my $ actions := $ ! actions ;
323
337
nqp ::findmethod($ actions , $ name )($ actions , $ match , $ key )
324
338
if ! nqp ::isnull($ actions ) && nqp :: can ($ actions , $ name );
325
339
}
@@ -1070,8 +1084,8 @@ class NQPCursor does NQPCursorRole {
1070
1084
}
1071
1085
1072
1086
method parse ($ target , : $ rule = ' TOP' , : $ actions , * % options ) {
1073
- my $ * ACTIONS := $ actions ;
1074
- my $ cur := self . ' !cursor_init ' ( $ target , | % options );
1087
+ my $ cur := self . ' !cursor_init ' ( $ target , : actions( $ actions ), | % options ) ;
1088
+
1075
1089
nqp ::isinvokable($ rule ) ??
1076
1090
$ rule ($ cur ). MATCH() !!
1077
1091
nqp ::findmethod($ cur , $ rule )($ cur ). MATCH()
0 commit comments