Skip to content

Commit f21c8f1

Browse files
committed
get rid of $*ACTIONS
The current actions class is now passed via the cursor.
1 parent 213f551 commit f21c8f1

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/HLL/Grammar.nqp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,13 @@ An operator precedence parser.
612612
}
613613

614614
method LANG($lang, $regex, *@args) {
615-
my $lang_cursor := %*LANG{$lang}.'!cursor_init'(self.orig(), :p(self.pos()), :shared(self.'!shared'()));
615+
my $actions := %*LANG{$lang ~ '-actions'};
616+
my $lang_cursor := %*LANG{$lang}.'!cursor_init'(self.orig(), :p(self.pos()), :shared(self.'!shared'()), actions => $actions);
616617
if self.HOW.traced(self) {
617618
$lang_cursor.HOW.trace-on($lang_cursor, self.HOW.trace_depth(self));
618619
}
619-
my $*ACTIONS := %*LANG{$lang ~ '-actions'};
620-
$lang_cursor."$regex"(|@args);
620+
my $result := $lang_cursor."$regex"(|@args);
621+
nqp::bindattr($result,NQPCursor,'$!actions', nqp::getattr(self, NQPCursor, '$!actions'));
622+
$result;
621623
}
622624
}

src/QRegex/Cursor.nqp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ role NQPCursorRole is export {
3535
has $!cstack;
3636
has $!regexsub;
3737
has $!restart;
38+
has $!actions;
3839

3940
method orig() { nqp::getattr($!shared, ParseShared, '$!orig') }
4041
method target() { nqp::getattr_s($!shared, ParseShared, '$!target') }
@@ -48,6 +49,14 @@ role NQPCursorRole is export {
4849
$!regexsub := NQPMu;
4950
}
5051

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+
5160
method !APPEND_TO_ORIG($value) {
5261
my $orig := nqp::getattr($!shared, ParseShared, '$!orig');
5362
$orig := $orig ~ $value;
@@ -115,7 +124,7 @@ role NQPCursorRole is export {
115124
$caps;
116125
}
117126

118-
method !cursor_init($orig, :$p = 0, :$c, :$shared, *%ignore) {
127+
method !cursor_init($orig, :$p = 0, :$c, :$shared, :$actions, *%ignore) {
119128
my $new := self.CREATE();
120129
unless $shared {
121130
$shared := nqp::create(ParseShared);
@@ -127,6 +136,7 @@ role NQPCursorRole is export {
127136
nqp::bindattr($shared, ParseShared, '%!marks', nqp::hash());
128137
}
129138
nqp::bindattr($new, $?CLASS, '$!shared', $shared);
139+
nqp::bindattr($new, $?CLASS, '$!actions', $actions);
130140
if nqp::defined($c) {
131141
nqp::bindattr_i($new, $?CLASS, '$!from', -1);
132142
nqp::bindattr_i($new, $?CLASS, '$!pos', $c);
@@ -150,6 +160,7 @@ role NQPCursorRole is export {
150160
# Uncomment following to log cursor creation.
151161
#$!shared.log_cc(nqp::getcodename($sub));
152162
nqp::bindattr($new, $?CLASS, '$!shared', $!shared);
163+
nqp::bindattr($new, $?CLASS, '$!actions', $!actions) if nqp::isconcrete(self);
153164
nqp::bindattr($new, $?CLASS, '$!regexsub', nqp::ifnull(nqp::getcodeobj($sub), $sub));
154165
if nqp::defined($!restart) {
155166
nqp::bindattr_i($new, $?CLASS, '$!pos', $!pos);
@@ -182,6 +193,7 @@ role NQPCursorRole is export {
182193
# Uncomment following to log cursor creation.
183194
#$!shared.log_cc(nqp::getcodename($sub));
184195
nqp::bindattr($new, $?CLASS, '$!shared', $!shared);
196+
nqp::bindattr($new, $?CLASS, '$!actions', $!actions) if nqp::isconcrete(self);
185197
nqp::bindattr($new, $?CLASS, '$!regexsub', nqp::ifnull(nqp::getcodeobj($sub), $sub));
186198
if nqp::defined($!restart) {
187199
nqp::bindattr_i($new, $?CLASS, '$!pos', $!pos);
@@ -205,6 +217,7 @@ role NQPCursorRole is export {
205217
# Uncomment following to log cursor creation.
206218
#$!shared.log_cc(nqp::getcodename($sub));
207219
nqp::bindattr($new, $?CLASS, '$!shared', $!shared);
220+
nqp::bindattr($new, $?CLASS, '$!actions', $!actions) if nqp::isconcrete(self);
208221
nqp::bindattr($new, $?CLASS, '$!regexsub', nqp::ifnull(nqp::getcodeobj($sub), $sub));
209222
if nqp::defined($!restart) {
210223
nqp::die("!cursor_start_cur cannot restart a cursor");
@@ -222,6 +235,7 @@ role NQPCursorRole is export {
222235
method !cursor_start_subcapture($from) {
223236
my $new := nqp::create(self);
224237
nqp::bindattr($new, $?CLASS, '$!shared', $!shared);
238+
nqp::bindattr($new, $?CLASS, '$!actions', $!actions) if nqp::isconcrete(self);
225239
nqp::bindattr_i($new, $?CLASS, '$!from', $from);
226240
nqp::bindattr_i($new, $?CLASS, '$!pos', -3);
227241
$new;
@@ -312,14 +326,14 @@ role NQPCursorRole is export {
312326
}
313327

314328
method !reduce(str $name) {
315-
my $actions := nqp::getlexdyn('$*ACTIONS');
329+
my $actions := $!actions;
316330
nqp::findmethod($actions, $name)($actions, self.MATCH)
317331
if !nqp::isnull($actions) && nqp::can($actions, $name);
318332
self;
319333
}
320334

321335
method !reduce_with_match(str $name, str $key, $match) {
322-
my $actions := nqp::getlexdyn('$*ACTIONS');
336+
my $actions := $!actions;
323337
nqp::findmethod($actions, $name)($actions, $match, $key)
324338
if !nqp::isnull($actions) && nqp::can($actions, $name);
325339
}
@@ -1070,8 +1084,8 @@ class NQPCursor does NQPCursorRole {
10701084
}
10711085

10721086
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+
10751089
nqp::isinvokable($rule) ??
10761090
$rule($cur).MATCH() !!
10771091
nqp::findmethod($cur, $rule)($cur).MATCH()

0 commit comments

Comments
 (0)