Skip Menu |
 

This queue is for tickets about the Regexp-Assemble CPAN distribution.

Report information
The Basics
Id: 50228
Status: open
Priority: 0/
Queue: Regexp-Assemble

People
Owner: dland [...] cpan.org
Requestors: dland [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.34
Fixed in: (no value)



Subject: Regexp::Assemble and possessive quantifiers
Dear David, I have noticed a major shortcoming and incompatibility in the Regexp::Assemble package. It seems that it does not handle possessive quantifiers correctly. This is especially problematic since both possessive quantifiers and regexp optimization are used for performace reasons, and therefore these techniques would commonly be used together. Regexp::Assemble considers the latter plus as a literal character, and for example the regexp "x++" is converted into "x+\+". While the case above can be simply converted back, it gets much more complicated if the plus is noticed as a common portion, for example from "foo++", "bar++" into "(foo+|bar+)\+". Does Regexp::Assemble contain any support for possessive quantifiers, or do you have any other suggestions how to work around the problem? Below is a test script that assembles and prints out a regexp using possessive quantifiers. I'm obliged for any help you can offer. Best regards, Sampo N. #!/usr/bin/perl use Regexp::Assemble; my $ra = Regexp::Assemble->new; $ra->add("x++"); print $ra->as_string() . "\n";
Download (untitled) / with headers
text/plain 510b
Show quoted text
> Does Regexp::Assemble contain any support for possessive quantifiers, or > do you have any other suggestions how to work around the problem?
Hacky workaround: my $re = Regexp::Assemble->new; for my $pat (qw(foo++d bar++d)) { my $arr = $re->lexstr($pat); print "@$arr\n"; for (my $n = 0; $n < $#$arr - 1; ++$n) { if ($arr->[$n] =~ /\+$/ and $arr->[$n+1] eq '+') { $arr->[$n] .= splice(@$arr, $n+1, 1); } } $re->insert(@$arr); } print $re->as_string(), $/;
Perhaps https://metacpan.org/release/Regexp-Parsertron will help in some way.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.