Skip to content

Commit 32d6a49

Browse files
committed
Start saving per-alternation NFAs.
1 parent d63dec6 commit 32d6a49

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/QRegex/P6Regex/Actions.nqp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
519519
:hll<nqp>, :namespace(['Sub']), :lexical(0),
520520
:name($block.subid ~ '_nfa'), $nfapast);
521521
$initpast.push(PAST::Stmt.new($nfablock));
522+
alt_nfas($qast, $block.subid, $initpast);
522523
}
523524

524525
unless $block.symbol('') {
@@ -586,6 +587,28 @@ class QRegex::P6Regex::Actions is HLL::Actions {
586587
%capnames{''} := $count;
587588
%capnames;
588589
}
590+
591+
sub alt_nfas($ast, $subid, $initpast) {
592+
my $rxtype := $ast.rxtype;
593+
if $rxtype eq 'alt' {
594+
my $nfapast := PAST::Op.new( :pasttype('list') );
595+
$ast.name(PAST::Node.unique('alt_nfa_'));
596+
for $ast.list {
597+
alt_nfas($_, $subid, $initpast);
598+
$nfapast.push(QRegex::NFA.new.addnode($_).past);
599+
}
600+
my $nfablock := PAST::Block.new(
601+
:hll<nqp>, :namespace(['Sub']), :lexical(0),
602+
:name($subid ~ '_' ~ $ast.name), $nfapast);
603+
$initpast.push(PAST::Stmt.new($nfablock));
604+
}
605+
elsif $rxtype eq 'subcapture' || $rxtype eq 'quant' {
606+
alt_nfas($ast[0], $subid, $initpast)
607+
}
608+
elsif $rxtype eq 'concat' || $rxtype eq 'altseq' || $rxtype eq 'conj' || $rxtype eq 'conjseq' {
609+
for $ast.list { alt_nfas($_, $subid, $initpast) }
610+
}
611+
}
589612

590613
method subrule_alias($ast, $name) {
591614
if $ast.name gt '' { $ast.name( $name ~ '=' ~ $ast.name ); }

0 commit comments

Comments
 (0)