Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement separator form of **

  • Loading branch information...
commit 25acd314e850bc688731c9cd7e4bee959c971c07 1 parent b94fd4d
@sorear authored
View
4 src/Niecza/Actions.pm
@@ -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 '') {
View
8 src/Optimizer/RxSimple.pm
@@ -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
5 src/RxOp.pm
@@ -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
1  test2.pl
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.