Skip to content

Commit e549cf2

Browse files
committed
Fix NFA generation for charrange with ignorecase.
1 parent 8013acd commit e549cf2

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/QRegex/NFA.nqp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,31 @@ class QRegex::NFA {
237237
method charrange($node, $from, $to) {
238238
my $indent := dentin();
239239
note("$indent charrange $from -> $to") if $nfadeb;
240-
if $node.subtype eq 'zerowidth' {
241-
$from := self.addedge($from, -1, $EDGE_CHARRANGE + ?$node.negate,
242-
[$node[1].value, $node[2].value]);
243-
dentout(self.addedge($from, 0, $EDGE_FATE, 0));
240+
my $base_edge := $EDGE_CHARRANGE;
241+
my @to_add;
242+
if $node[0] eq 'ignorecase' || $node[0] eq 'ignorecase+ignoremark' {
243+
nqp::push(@to_add, nqp::ord(nqp::lc(nqp::chr($node[1].value))));
244+
nqp::push(@to_add, nqp::ord(nqp::lc(nqp::chr($node[2].value))));
245+
nqp::push(@to_add, nqp::ord(nqp::uc(nqp::chr($node[1].value))));
246+
nqp::push(@to_add, nqp::ord(nqp::uc(nqp::chr($node[2].value))));
244247
}
245248
else {
246-
dentout(self.addedge($from, $to, $EDGE_CHARRANGE + ?$node.negate,
247-
[$node[1].value, $node[2].value]));
249+
nqp::push(@to_add, $node[1].value);
250+
nqp::push(@to_add, $node[2].value);
251+
}
252+
my $result;
253+
for @to_add -> $ord0, $ord1 {
254+
if $node.subtype eq 'zerowidth' {
255+
my $next := self.addedge($from, -1, $base_edge + ?$node.negate,
256+
[$ord0, $ord1]);
257+
$result := dentout(self.addedge($next, 0, $EDGE_FATE, 0));
258+
}
259+
else {
260+
$result := dentout(self.addedge($from, $to, $base_edge + ?$node.negate,
261+
[$ord0, $ord1]));
262+
}
248263
}
264+
$result
249265
}
250266

251267
method literal($node, $from, $to) {

0 commit comments

Comments
 (0)