Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
trash my crappy quant NFA generator (lots of bad code); replace with …
…one that works and handles % (and %%)
  • Loading branch information
diakopter committed May 27, 2012
1 parent 9befba5 commit 996ac93
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/QRegex/NFA.nqp
Expand Up @@ -140,28 +140,22 @@ class QRegex::NFA {

# handle only ?,*,+ for now
return self.fate($node, $from, $to) if $max > 1 || $min > 1;
if $max == -1 {
if $min == 0 { # * quantifier
my $st := self.regex_nfa($node[0], $from, $from);
$st := self.addedge($from, $to, $EDGE_EPSILON, 0);
$to := $st if $to < 0 && $st > 0;
} else { # + quantifier
my $start := self.addstate();
self.addedge($from, $start, $EDGE_EPSILON, 0);
my $looper := self.addstate();
my $st := self.regex_nfa($node[0], $start, $looper);
self.addedge($looper, $start, $EDGE_EPSILON, 0);
self.addedge($looper, $to, $EDGE_EPSILON, 0);
$to := $st if $to < 0 && $st > 0;

if $max == 1 || ($min == 0 && $max == 1) {
my $st := self.addstate();
self.addedge($from, $st, $EDGE_EPSILON, 0);
self.addedge($from, $to, $EDGE_EPSILON, 0) if $min == 0;
my $atom := self.regex_nfa($node[0], $st, $to);
if pir::defined($node[1]) {
self.regex_nfa($node[1], $atom, $atom) if pir::defined($node[1]);
}
elsif $max == -1 {
self.addedge($atom, $st, $EDGE_EPSILON, 0)
}
$to;
} elsif $min == 0 && $max == 1 { # ? quantifier
my $st := self.regex_nfa($node[0], $from, $to);
$to := $st if $to < 0 && $st > 0;
$st := self.addedge($from, $to, $EDGE_EPSILON, 0);
$to := $st if $to < 0 && $st > 0;
$to;
} else {
$to
}
else {
self.fate($node, $from, $to)
}
}
Expand Down

0 comments on commit 996ac93

Please sign in to comment.