Skip to content

Commit 8ea85a9

Browse files
committed
Refactor mergesubrule a bit.
1 parent 4903492 commit 8ea85a9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/QRegex/NFA.nqp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,21 @@ class QRegex::NFA {
135135
my $subrule := $cursor.HOW.find_method($cursor, $name);
136136
my @substates := $subrule.nqpattr('nfa') if $subrule;
137137
if @substates {
138-
# append a clone of the new states to our states
139-
my $substart := nqp::elems($!states);
140-
for @substates { nqp::push($!states, nqp::clone($_)) }
141-
my $subend := nqp::elems($!states);
138+
# create an empty end state for the subrule's NFA
139+
my $substart := self.addstate();
140+
# Copy (yes, clone) @substates[1..*] into our states.
141+
# We have to clone because we'll be modifying the
142+
# values for use in this particular NFA.
143+
@substates := nqp::clone(@substates);
144+
nqp::shift(@substates);
145+
nqp::push($!states, nqp::clone(nqp::shift(@substates)))
146+
while @substates;
142147
# Go through all of the newly added states, and
143148
# apply $substart offset to target states
144149
# adjust fate edges to be $fate
145150
# append any subrules
146-
my $i := $substart;
151+
my $subend := nqp::elems($!states);
152+
my $i := $substart;
147153
while $i < $subend {
148154
my $substate := $!states[$i];
149155
my $j := 0;

0 commit comments

Comments
 (0)