Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix /(x|y)/ case; tracking :dba immediately while parsing
  • Loading branch information
sorear committed Oct 27, 2011
1 parent 52fdc3b commit 67f9b80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 73 deletions.
45 changes: 19 additions & 26 deletions src/NieczaActions.pm6
Expand Up @@ -327,13 +327,6 @@ method rxembed($/, $op, $) {
method op_for_regex($/, $rxop) {
my @lift = $rxop.oplift;
{
my $*paren = 0;
my $*dba = 'anonymous rule';
my $*symtext;
my $*endsym;
$rxop.check
}
my ($orxop, $mb) = ::GLOBAL::OptRxSimple.run($rxop);
my $sub = self.thunk_sub(::Op::RegexBody.new(|node($/),
canback => $mb, pre => @lift, rxop => $orxop),
Expand Down Expand Up @@ -394,46 +387,42 @@ method regex_def_2 ($, $/ = $*cursor) {
if $<signature> > 1 {
$/.CURSOR.sorry("Too many signatures on regex");
}
}

method regex_def($/) {
my $endsym;
for map *.ast, @$<trait> -> $t {
if $t<unary> || $t<binary> || $t<defequiv> || $t<of> {
# Ignored for now
}
elsif defined $t<endsym> {
$endsym = $t<endsym>;
%*RX<endsym> = $t<endsym>;
}
else {
$/.CURSOR.sorry("Unhandled regex trait $t.keys.[0]");
}
}

if $*CURLEX<!multi> eq 'proto' {
if ($<signature> && $<signature>[0].ast.params != 1) ||
!$<regex_block><onlystar> {
$/.CURSOR.sorry('Only {*} protoregexes with no parameters are supported');
}
@*MEMOS[0]<proto_endsym>{$*CURLEX<!cleanname>} = $endsym
@*MEMOS[0]<proto_endsym>{$*CURLEX<!cleanname>} = %*RX<endsym>
if defined $*CURLEX<!cleanname>;
} else {
$endsym //= @*MEMOS[0]<proto_endsym>{$*CURLEX<!cleanname>} if
%*RX<endsym> //= @*MEMOS[0]<proto_endsym>{$*CURLEX<!cleanname>} if
defined $*CURLEX<!cleanname>;
}

%*RX<dba> = $*CURLEX<!name> // 'anonymous regex';
}

method regex_def($/) {
my $ast = $<regex_block>.ast;

if $*CURLEX<!multi> eq 'proto' {
if ($<signature> && $<signature>[0].ast.params != 1) ||
!$<regex_block><onlystar> {
$/.CURSOR.sorry('Only {*} protoregexes with no parameters are supported');
}

$ast = ::RxOp::ProtoRedis.new(name => $*CURLEX<!name>);
}

{
my $*paren = 0;
my $*symtext = $*CURLEX<!sym>;
my $*endsym = $endsym;
my $*dba = $*CURLEX<!name> // 'anonymous regex';
$ast.check;
}
my @lift = $ast.oplift;
my $ltm = ::GLOBAL::OptRxSimple.run_lad($ast.lad);
$*CURLEX<!sub>.set_ltm($ltm);
Expand Down Expand Up @@ -720,7 +709,7 @@ method do_cclass($/) {
$rxop = ::RxOp::CClassElem.new(cc => ($rxop ?? $rxop.cc !! $CClass::Full).minus($exp.cc));
}
} elsif $sign {
$rxop = $rxop ?? ::RxOp::SeqAlt.new(zyg => [ $exp, $rxop ]) !! $exp;
$rxop = $rxop ?? ::RxOp::SeqAlt.new(zyg => [ $exp, $rxop ], dba => %*RX<dba>) !! $exp;
} else {
$rxop = ::RxOp::Sequence.new(zyg => [
::RxOp::NotBefore.new(zyg => [ $exp ]),
Expand Down Expand Up @@ -752,7 +741,10 @@ method assertion:name ($/) {
if $<assertion> {
make $<assertion>.ast;
} elsif $name eq 'sym' {
make ::RxOp::Sym.new(igcase => %*RX<i>, igmark => %*RX<a>);
$/.CURSOR.sorry("<sym> is only valid in multiregexes")
unless defined %*RX<sym>;
make ::RxOp::Sym.new(igcase => %*RX<i>, igmark => %*RX<a>,
text => %*RX<sym> // '', endsym => %*RX<endsym>);
} elsif $name eq 'before' {
make ::RxOp::Before.new(zyg => [$<nibbler>[0].ast]);
return Nil;
Expand Down Expand Up @@ -3238,6 +3230,7 @@ method install_sub($/, $sub, :$multiness is copy, :$scope is copy, :$class,
($name ~~ /\:sym\<(.*)\>/) ?? ($name.substr(0, $/.from), ~$0) !!
($name ~~ /\:(\w+)/) ?? ($name.substr(0, $/.from), ~$0) !!
($name, Str);
%*RX<sym> = $*CURLEX<!sym>;
$multiness = 'multi' if defined $*CURLEX<!sym>;
$*CURLEX<!multi> = $multiness;
}
Expand Down
47 changes: 0 additions & 47 deletions src/RxOp.pm6
Expand Up @@ -10,7 +10,6 @@ method ctxopzyg() { map *.ctxopzyg, @$!zyg }
method oplift() { map *.oplift, @$!zyg }
method uncut() { self }

method check() { for @$!zyg { $_.check } }
method tocclist() { CClass }

# all that matters is 0-1-infty; $*in_quant valid here
Expand All @@ -31,17 +30,6 @@ method label() { "b" ~ ($nlabel++) }
class Capturing is RxOp {
has $.captures = []; # Array of Str

method check() {
for @$.captures -> $c is rw {
if !defined($c) {
$c = $*paren++;
} elsif $c ~~ /^<[ 0..9 ]>+$/ {
$*paren = $c + 1;
}
}
for @$.zyg { $_.check }
}

method used_caps() {
my %h = map { ($_ => $*in_quant ?? 2 !! 1) }, @$.captures;
%h
Expand All @@ -59,8 +47,6 @@ class Sym is Capturing {
:$captures);
}

method check() { $.text = $*symtext; $.endsym = $*endsym; nextsame }

method code($body) { #OK not used
my $t = $.text;
# We aren't going to make a real Match unless somebody comes up with
Expand Down Expand Up @@ -278,19 +264,6 @@ class Sequence is RxOp {
class AltBase is RxOp {
has $.dba; # Str

method check() {
my $maxparen = $*paren;
$!dba //= ($*dba // die "wtf no dba");

for @$.zyg {
temp $*paren;
$_.check;
if ($*paren > $maxparen) { $maxparen = $*paren }
}

$*paren = $maxparen;
}

method used_caps() {
my %used;
for @$.zyg -> $x {
Expand All @@ -304,7 +277,6 @@ class AltBase is RxOp {
}

class SeqAlt is AltBase {
has $.dba; # is rw, Str
# zyg * N

method code($body) {
Expand Down Expand Up @@ -425,11 +397,6 @@ class Tilde is RxOp {
has $.closer = die "Tilde.closer required"; # Str
has $.dba;

method check() {
$!dba //= $*dba;
nextsame;
}

method code($body) {
my @code;
my $fail = self.label;
Expand Down Expand Up @@ -485,18 +452,6 @@ class Subrule is Capturing {
%h
}

method check() {
if $!_passcapzyg {
if $!passcap {
$!_passcapzyg.check;
} else {
my $*paren = 0;
$!_passcapzyg.check;
}
}
nextsame;
}

method code($body) {
my $callf = $!regex ?? $!regex.cgop($body) !!
CgOp.methodcall(CgOp.rxcall("MakeCursorV"),
Expand Down Expand Up @@ -569,8 +524,6 @@ class Alt is AltBase {
my @lads = @( $.optimized_lads // (map { $_.lad }, @$.zyg) );
my $end = self.label;

die "check screwed up" unless defined $.dba;

my @code;
push @code, CgOp.ltm_push_alts([@lads], $.dba, [@ls]);
push @code, CgOp.goto('backtrack');
Expand Down
2 changes: 2 additions & 0 deletions src/STD.pm6
Expand Up @@ -427,6 +427,8 @@ token escape:none { <!> }
# and this is what makes nibbler polymorphic...
method nibble ($lang) {
temp %*RX; # prevent up-vars from leaking
%*RX<dba> = 'anonymous regex';
# leave endsym, sym undefined
self.cursor_fresh($lang).nibbler;
}

Expand Down

0 comments on commit 67f9b80

Please sign in to comment.