Skip to content

Commit

Permalink
Update to work with latest NQP.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 3, 2013
1 parent 02001c7 commit caf2b43
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
7 changes: 3 additions & 4 deletions lib/QAST/JASTCompiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3919,7 +3919,6 @@ class QAST::CompilerJAST {
%cclass_code<s> := nqp::const::CCLASS_WHITESPACE;
%cclass_code<w> := nqp::const::CCLASS_WORD;
%cclass_code<n> := nqp::const::CCLASS_NEWLINE;
%cclass_code<nl> := nqp::const::CCLASS_NEWLINE;
}

method cclass($node) {
Expand All @@ -3930,8 +3929,8 @@ class QAST::CompilerJAST {
$il.append(JAST::Instruction.new( :op('lcmp') ));
$il.append(JAST::Instruction.new( :op('ifge'), %*REG<fail> ));

my $subtype := nqp::lc($node.subtype);
self.panic("Unrecognized subtype '$subtype' in QAST::Regex cclass")
my $subtype := nqp::lc($node.name);
nep::die("Unrecognized subtype '$subtype' in QAST::Regex cclass")
unless nqp::existskey(%cclass_code, $subtype);
my $cclass := %cclass_code{$subtype};
if $subtype ne '.' {
Expand All @@ -3943,7 +3942,7 @@ class QAST::CompilerJAST {
$il.append(JAST::Instruction.new( :op('l2i') ));
$il.append(JAST::Instruction.new( :op($node.negate ?? 'ifne' !! 'ifeq'), %*REG<fail> ));

if $subtype eq 'nl' {
if $subtype == nqp::const::CCLASS_NEWLINE {
$il.append(JAST::Instruction.new( :op('aload'), %*REG<tgt> ));
$il.append(JAST::Instruction.new( :op('lload'), %*REG<pos> ));
$il.append(JAST::Instruction.new( :op('l2i') ));
Expand Down
27 changes: 12 additions & 15 deletions nqp-src/NQPP6QRegex.pm
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
}

method metachar:sym<.>($/) {
make QAST::Regex.new( :rxtype<cclass>, :subtype<.>, :node($/) );
make QAST::Regex.new( :rxtype<cclass>, :name<.>, :node($/) );
}

method metachar:sym<^>($/) {
Expand Down Expand Up @@ -585,8 +585,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
method metachar:sym<mod>($/) { make $<mod_internal>.ast; }

method backslash:sym<s>($/) {
make QAST::Regex.new(:rxtype<cclass>, '.CCLASS_WHITESPACE',
:subtype($<sym> eq 'n' ?? 'nl' !! ~$<sym>),
make QAST::Regex.new(:rxtype<cclass>, :name( nqp::lc(~$<sym>) ),
:negate($<sym> le 'Z'), :node($/));
}

Expand Down Expand Up @@ -747,20 +746,18 @@ class QRegex::P6Regex::Actions is HLL::Actions {
$qast.subtype('zerowidth');
$qast := QAST::Regex.new(:rxtype<concat>, :node($/),
$qast,
QAST::Regex.new( :rxtype<cclass>, :subtype<.> ));
QAST::Regex.new( :rxtype<cclass>, :name<.> ));
}

my $i := 1;
my $n := +$clist;
while $i < $n {
my $ast := $clist[$i].ast;
if $ast.negate {
if $ast.rxtype eq 'cclass' {
$ast := QAST::Regex.new( :rxtype<conj>, :subtype<zerowidth>, $ast );
}
else {
$ast.subtype('zerowidth');
}
$qast := QAST::Regex.new( $ast, $qast, :rxtype<concat>, :node($/));
if $ast.negate || $ast.rxtype eq 'cclass' && ~$ast.node le 'Z' {
$ast.subtype('zerowidth');
$qast := QAST::Regex.new( :rxtype<concat>, :node($/), :subtype<zerowidth>, :negate(1),
QAST::Regex.new( :rxtype<conj>, :subtype<zerowidth>, $ast ),
$qast );
}
else {
$qast := QAST::Regex.new( $qast, $ast, :rxtype<altseq>, :node($/));
Expand Down Expand Up @@ -833,6 +830,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
elsif $_[0]<backslash> {
my $bs := $_[0]<backslash>.ast;
$bs.negate(!$bs.negate) if $<sign> eq '-';
$bs.subtype('zerowidth') if $bs.negate;
@alts.push($bs);
}
else { $str := $str ~ ~$_[0]; }
Expand All @@ -841,12 +839,11 @@ class QRegex::P6Regex::Actions is HLL::Actions {
if nqp::chars($str);
$qast := +@alts == 1 ?? @alts[0] !!
$<sign> eq '-' ??
QAST::Regex.new( :rxtype<concat>, :node($/),
QAST::Regex.new( :rxtype<concat>, :node($/), :subtype<zerowidth>, :negate(1),
QAST::Regex.new( :rxtype<conj>, :subtype<zerowidth>, |@alts ),
QAST::Regex.new( :rxtype<cclass>, :subtype<.> ) ) !!
QAST::Regex.new( :rxtype<cclass>, :name<.> ) ) !!
QAST::Regex.new( :rxtype<altseq>, |@alts );
}
#$qast.negate( $<sign> eq '-' );
make $qast;
}

Expand Down
2 changes: 1 addition & 1 deletion nqp-src/QRegex.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class QRegex::NFA {

method cclass($node, $from, $to) {
self.addedge($from, $to, $EDGE_CHARCLASS + ?$node.negate,
%cclass_code{nqp::lc($node.subtype)});
%cclass_code{nqp::lc($node.name)});
}

method concat($node, $from, $to) {
Expand Down

0 comments on commit caf2b43

Please sign in to comment.