Skip to content

Commit acdaae4

Browse files
committed
Revert diakopter++'s NFA changes.
Unfortunately, they break various NQP tests and the Rakudo build.
1 parent d05da7c commit acdaae4

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/QRegex/NFA.nqp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,28 @@ class QRegex::NFA {
140140

141141
# handle only ?,*,+ for now
142142
return self.fate($node, $from, $to) if $max > 1 || $min > 1;
143-
144-
if $max == -1 || ($min == 0 && $max == 1) {
145-
my $st := self.addstate();
146-
self.addedge($from, $st, $EDGE_EPSILON, 0);
147-
self.addedge($from, $to, $EDGE_EPSILON, 0) if $min == 0;
148-
my $atom := self.regex_nfa($node[0], $st, $to);
149-
if pir::defined($node[1]) {
150-
self.regex_nfa($node[1], $atom, $atom) if pir::defined($node[1]);
151-
}
152-
elsif $max == -1 {
153-
self.addedge($atom, $st, $EDGE_EPSILON, 0)
143+
if $max == -1 {
144+
if $min == 0 { # * quantifier
145+
my $st := self.regex_nfa($node[0], $from, $from);
146+
$st := self.addedge($from, $to, $EDGE_EPSILON, 0);
147+
$to := $st if $to < 0 && $st > 0;
148+
} else { # + quantifier
149+
my $start := self.addstate();
150+
self.addedge($from, $start, $EDGE_EPSILON, 0);
151+
my $looper := self.addstate();
152+
my $st := self.regex_nfa($node[0], $start, $looper);
153+
self.addedge($looper, $start, $EDGE_EPSILON, 0);
154+
self.addedge($looper, $to, $EDGE_EPSILON, 0);
155+
$to := $st if $to < 0 && $st > 0;
154156
}
157+
$to;
158+
} elsif $min == 0 && $max == 1 { # ? quantifier
159+
my $st := self.regex_nfa($node[0], $from, $to);
155160
$to := $st if $to < 0 && $st > 0;
156-
$to
157-
}
158-
else {
161+
$st := self.addedge($from, $to, $EDGE_EPSILON, 0);
162+
$to := $st if $to < 0 && $st > 0;
163+
$to;
164+
} else {
159165
self.fate($node, $from, $to)
160166
}
161167
}

0 commit comments

Comments
 (0)