Permalink
Browse files

Implement separator form of **

  • Loading branch information...
1 parent b94fd4d commit 25acd314e850bc688731c9cd7e4bee959c971c07 @sorear committed Sep 16, 2010
Showing with 11 additions and 7 deletions.
  1. +3 −1 src/Niecza/Actions.pm
  2. +4 −4 src/Optimizer/RxSimple.pm
  3. +3 −2 src/RxOp.pm
  4. +1 −0 test2.pl
View
@@ -423,8 +423,10 @@ sub quantified_atom { my ($cl, $M) = @_; # :: RxOp
}
if (defined $q->{min}) {
+ my @z = $atom;
+ push @z, $q->{sep} if defined $q->{sep};
$atom = RxOp::Quantifier->new(min => $q->{min}, max => $q->{max},
- zyg => [$atom], minimal => ($q->{mod} && $q->{mod} eq '?'));
+ zyg => [@z], minimal => ($q->{mod} && $q->{mod} eq '?'));
}
if (defined $q->{mod} && $q->{mod} eq '') {
@@ -181,12 +181,12 @@ sub RxOp::NotBefore::rxsimp { my ($self, $cut) = @_;
}
sub RxOp::Quantifier::rxsimp { my ($self, $cut) = @_;
- my $z = $self->zyg->[0]->rxsimp(0);
- if ($cut && $z->isa('RxOp::CClassElem')) {
- return RxOp::QuantCClass->new(cc => $z->cc, min => $self->min,
+ my @z = map { $_->rxsimp(0) } @{ $self->zyg };
+ if ($cut && @z == 1 && $z[0]->isa('RxOp::CClassElem')) {
+ return RxOp::QuantCClass->new(cc => $z[0]->cc, min => $self->min,
max => $self->max);
}
- return RxOp::Quantifier->new(%$self, zyg => [$z]);
+ return RxOp::Quantifier->new(%$self, zyg => [@z]);
}
sub RxOp::QuantCClass::mayback { 0 }
View
@@ -85,14 +85,13 @@ use CgOp;
has min => (isa => 'Int', is => 'ro', required => 1);
has max => (isa => 'Maybe[Int]', is => 'ro', default => undef);
- sub used_caps { local $::in_quant = 1; $_[0]->zyg->[0]->used_caps }
+ sub used_caps { local $::in_quant = 1; $_[0]->SUPER::used_caps }
sub code {
my ($self, $body) = @_;
my @code;
die "minimal matching NYI" if $self->minimal;
- die "separators NYI" if $self->zyg->[1];
my $exit = $self->label;
my $repeat = $self->label;
@@ -133,6 +132,8 @@ use CgOp;
CgOp::int($max)));
}
+ push @code, $self->zyg->[1]->code($body)
+ if $self->zyg->[1];
push @code, CgOp::label($middle) if $min;
push @code, $self->zyg->[0]->code($body);
push @code, CgOp::rxcall('IncQuant') if $usequant;
View
@@ -42,6 +42,7 @@ sub redo {
rxtest /^ x**2..4 $/, 'x**2..4', ('xx','xxx','xxxx'), ('x','xxxxx');
rxtest /^ x**2..* $/, 'x**2..*', ('xx','xxx','xxxx'), ('x',);
rxtest /^ [x**2] $/, 'x**2', ('xx',), ('x','xxx');
+ rxtest /^ [x**y] $/, 'x**y', ('x','xyx','xyxyx'), ('','xy','yx');
}
done-testing;

0 comments on commit 25acd31

Please sign in to comment.