Created
February 25, 2013 23:36
-
-
Save FROGGS/5034374 to your computer and use it in GitHub Desktop.
cclass oddity 2000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/QRegex/P6Regex/Actions.nqp b/src/QRegex/P6Regex/Actions.nqp | |
index dff6757..1ab5bc3 100755 | |
--- a/src/QRegex/P6Regex/Actions.nqp | |
+++ b/src/QRegex/P6Regex/Actions.nqp | |
@@ -432,6 +432,7 @@ class QRegex::P6Regex::Actions is HLL::Actions { | |
while $i < $n { | |
my $ast := $clist[$i].ast; | |
if $ast.negate { | |
+ say("method assertion:sym<[>($/) while negate"); | |
if $ast.rxtype eq 'cclass' { | |
$ast := QAST::Regex.new( :rxtype<conj>, :subtype<zerowidth>, $ast ); | |
} | |
@@ -441,6 +442,7 @@ class QRegex::P6Regex::Actions is HLL::Actions { | |
$qast := QAST::Regex.new( $ast, $qast, :rxtype<concat>, :node($/)); | |
} | |
else { | |
+ say("method assertion:sym<[>($/) while !negate"); | |
$qast := QAST::Regex.new( $qast, $ast, :rxtype<altseq>, :node($/)); | |
} | |
$i++; | |
@@ -464,21 +466,25 @@ class QRegex::P6Regex::Actions is HLL::Actions { | |
my $str := ''; | |
my $qast; | |
if $<name> { | |
+ say("method cclass_elem($/) name"); | |
my $name := ~$<name>; | |
$qast := QAST::Regex.new( :rxtype<subrule>, :subtype<method>, | |
:negate( $<sign> eq '-' ), :node($/), | |
QAST::Node.new(QAST::SVal.new( :value($name) )) ); | |
} | |
elsif $<uniprop> { | |
+ say("method cclass_elem($/) uniprop"); | |
my $uniprop := ~$<uniprop>; | |
$qast := QAST::Regex.new( $uniprop, :rxtype<uniprop>, | |
:negate( $<sign> eq '-' && $<invert> ne '!' # $<sign> ^^ $<invert> | |
|| $<sign> ne '-' && $<invert> eq '!' ), :node($/) ); | |
} | |
else { | |
+ say("method cclass_elem($/) else"); | |
my @alts; | |
for $<charspec> { | |
if $_[1] { | |
+ say("method cclass_elem($/) else if"); | |
my $node; | |
my $lhs; | |
my $rhs; | |
@@ -509,11 +515,17 @@ class QRegex::P6Regex::Actions is HLL::Actions { | |
$str := nqp::concat($str, nqp::chr($ord0++)) while $ord0 <= $ord1; | |
} | |
elsif $_[0]<backslash> { | |
+ say("method cclass_elem($/) else elsif"); | |
my $bs := $_[0]<backslash>.ast; | |
+ say($_[0]<backslash>); | |
+ say("bs.negate = " ~ $bs.negate); | |
$bs.negate(!$bs.negate) if $<sign> eq '-'; | |
@alts.push($bs); | |
} | |
- else { $str := $str ~ ~$_[0]; } | |
+ else { | |
+ say("method cclass_elem($/) else else"); | |
+ $str := $str ~ ~$_[0]; | |
+ } | |
} | |
@alts.push(QAST::Regex.new( $str, :rxtype<enumcharlist>, :node($/), :negate( $<sign> eq '-' ) )) | |
if nqp::chars($str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./nqp -e 'say("[" ~ ("ab123c" ~~ /<[\w]-[a]>+/) ~ "]")' | |
method cclass_elem([\w]) else | |
method cclass_elem([\w]) else elsif | |
w | |
bs.negate = 0 | |
method cclass_elem(-[a]) else | |
method cclass_elem(-[a]) else else | |
method assertion:sym<[>([\w]-[a]) while negate | |
[b123c] | |
./nqp -e 'say("[" ~ ("ab123c" ~~ /<[\w]-[a\w]>+/) ~ "]")' | |
method cclass_elem([\w]) else | |
method cclass_elem([\w]) else elsif | |
w | |
bs.negate = 0 | |
method cclass_elem(-[a\w]) else | |
method cclass_elem(-[a\w]) else else | |
method cclass_elem(-[a\w]) else elsif | |
w | |
bs.negate = 0 | |
method assertion:sym<[>([\w]-[a\w]) while !negate | |
[ab123c] | |
-- | |
you can see that adding \w has effects to assertion:sym<[>, so this one thinks the second cclass isnt negated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/QRegex/P6Regex/Actions.nqp 2013-02-26 00:24:40.000000000 +0100 | |
+++ src/QRegex/P6Regex/Actions.nqp 2013-02-26 00:25:04.000000000 +0100 | |
@@ -536,7 +536,7 @@ | |
QAST::Regex.new( :rxtype<cclass>, :subtype<.> ) ) !! | |
QAST::Regex.new( :rxtype<altseq>, |@alts ); | |
} | |
- #$qast.negate( $<sign> eq '-' ); | |
+ $qast.negate( $<sign> eq '-' ); | |
make $qast; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./nqp -e 'say("[" ~ ("ab123c" ~~ /<[\w]-[a]>+/) ~ "]")' | |
method cclass_elem([\w]) else | |
method cclass_elem([\w]) else elsif | |
w | |
bs.negate = 0 | |
method cclass_elem(-[a]) else | |
method cclass_elem(-[a]) else else | |
method assertion:sym<[>([\w]-[a]) while negate | |
[b123c] | |
./nqp -e 'say("[" ~ ("ab123c" ~~ /<[\w]-[a\w]>+/) ~ "]")' | |
method cclass_elem([\w]) else | |
method cclass_elem([\w]) else elsif | |
w | |
bs.negate = 0 | |
method cclass_elem(-[a\w]) else | |
method cclass_elem(-[a\w]) else else | |
method cclass_elem(-[a\w]) else elsif | |
w | |
bs.negate = 0 | |
method assertion:sym<[>([\w]-[a\w]) while negate | |
[] | |
-- | |
now the second cclass stays negated, and the regex works... but: | |
./nqp -e 'say("[" ~ ("ab123c" ~~ /<[\w]-[a\d]>+/) ~ "]")' | |
method cclass_elem([\w]) else | |
method cclass_elem([\w]) else elsif | |
w | |
bs.negate = 0 | |
method cclass_elem(-[a\d]) else | |
method cclass_elem(-[a\d]) else else | |
method cclass_elem(-[a\d]) else elsif | |
d | |
bs.negate = 0 | |
method assertion:sym<[>([\w]-[a\d]) while negate | |
[b1] | |
-- | |
/o\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment