Skip to content

Commit

Permalink
Implement separator form of **
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 16, 2010
1 parent b94fd4d commit 25acd31
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Niecza/Actions.pm
Expand Up @@ -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 '') {
Expand Down
8 changes: 4 additions & 4 deletions src/Optimizer/RxSimple.pm
Expand Up @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions src/RxOp.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test2.pl
Expand Up @@ -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.