Skip to content

Commit

Permalink
Fix NFA of literals to handle NFG synthetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Nov 11, 2015
1 parent 367c227 commit ffdc843
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/QRegex/NFA.nqp
Expand Up @@ -268,6 +268,14 @@ class QRegex::NFA {
$result
}

# Synthetics must be conveyed as strings; anything else can go as an
# integer
sub ord-or-str($str, $idx) {
my int $ord := nqp::ord($str, $idx);
my str $chr := nqp::substr($str, $idx, 1);
nqp::chr($ord) eq $chr ?? $ord !! $chr
}

method literal($node, $from, $to) {
my $indent := dentin();
my int $litlen := nqp::chars($node[0]) - 1;
Expand All @@ -279,11 +287,11 @@ class QRegex::NFA {
my str $litconst_uc := nqp::uc($node[0]);
while $i < $litlen {
$from := self.addedge($from, -1, $EDGE_CODEPOINT_I,
[nqp::ord($litconst_lc, $i), nqp::ord($litconst_uc, $i)]);
[ord-or-str($litconst_lc, $i), ord-or-str($litconst_uc, $i)]);
$i := $i + 1;
}
dentout(self.addedge($from, $to, $!LITEND ?? $EDGE_CODEPOINT_I !! $EDGE_CODEPOINT_I_LL,
[nqp::ord($litconst_lc, $i), nqp::ord($litconst_uc, $i)]));
[ord-or-str($litconst_lc, $i), ord-or-str($litconst_uc, $i)]));
}
elsif $node.subtype eq 'ignoremark' {
my str $litconst := $node[0];
Expand All @@ -309,10 +317,11 @@ class QRegex::NFA {
else {
my str $litconst := $node[0];
while $i < $litlen {
$from := self.addedge($from, -1, $EDGE_CODEPOINT, nqp::ord($litconst, $i));
$from := self.addedge($from, -1, $EDGE_CODEPOINT, ord-or-str($litconst, $i));
$i := $i + 1;
}
dentout(self.addedge($from, $to, $!LITEND ?? $EDGE_CODEPOINT !! $EDGE_CODEPOINT_LL, nqp::ord($litconst, $i)));
dentout(self.addedge($from, $to, $!LITEND ?? $EDGE_CODEPOINT !! $EDGE_CODEPOINT_LL,
ord-or-str($litconst, $i)));
}
}
else {
Expand Down

0 comments on commit ffdc843

Please sign in to comment.