Skip Menu |

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

Report information
The Basics
Id: 42096
Status: resolved
Priority: 0/
Queue: Regexp-Parser

People
Owner: TODDR [...] cpan.org
Requestors: kentfredric [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.20
Fixed in: 0.20_01



Subject: [Patch] Test cases and using modules emit lots of noise under perls >5.10
Under perls 5.10 and greater, any program requiring Handlers.pm causes a warning notice to be emitted, t/01simple......Variable "$nest" is not available at (re_eval 2) line 2. Variable "$nest" is not available at (re_eval 3) line 2. This can be extremely annoying. All the test cases I've looked at for Show quoted text
>5.10 show this behaviour.
5.11: ( Problem ) http://www.nntp.perl.org/group/perl.cpan.testers/2007/12/msg877280.html 5.10: ( Problem ) http://www.nntp.perl.org/group/perl.cpan.testers/2007/09/msg623315.html 5.8 : ( No Problem ) http://www.nntp.perl.org/group/perl.cpan.testers/2008/11/msg2591886.html This appears to stem from the use of $name = qr[(??{ $name })] code, which can be also a bit hard to understand. Attached is the same qr[] blocks re-written using perl5.10's named references, which quietens down the problem a little.
Subject: Regexp-Parser-0.20-perl510reg.patch
diff -Naur Regexp-Parser-0.20/lib/Regexp/Parser/Handlers.pm Regexp-Parser-0.20/lib/Regexp/Parser/Handlers.pm --- Regexp-Parser-0.20/lib/Regexp/Parser/Handlers.pm 2004-07-07 01:38:26.000000000 +1200 +++ Regexp-Parser-0.20/lib/Regexp/Parser/Handlers.pm 2009-01-02 21:59:05.960525624 +1300 @@ -697,7 +697,21 @@ $self->add_handler('(?{' => sub { my ($S) = @_; my $nest; - $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; + $nest = qr[ + (?<recursion> # Named Capture Group + (?> # No BackTrack + [^\\{}]+ # No slash or braces + | # Or + \\. # Slash Dot + | # Or + { # Open Brace + (?&recursion) # Recurse Into this code again + } # Close Brace + )* # Repeated 0 or more times + ) # End Named Capture + ]x; + +# $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; if (${&Rx} =~ m{ \G ($nest) \} \) }xgc) { push @{ $S->{flags} }, &Rf; return $S->object(eval => $1); @@ -722,7 +736,20 @@ $self->add_handler('(??{' => sub { my ($S) = @_; my $nest; - $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; + $nest = qr[ + (?<recursion> # Named Capture Group + (?> # No BackTrack + [^\\{}]+ # No slash or braces + | # Or + \\. # Slash Dot + | # Or + { # Open Brace + (?&recursion) # Recurse Into this code again + } # Close Brace + )* # Repeated 0 or more times + ) # End Named Capture + ]x; + if (${&Rx} =~ m{ \G ($nest) \} \) }xgc) { push @{ $S->{flags} }, &Rf; return $S->object(logical => $1);
On Fri Jan 02 05:44:38 2009, kentfredric@gmail.com wrote: Show quoted text
> > Attached is the same qr[] blocks re-written using perl5.10's named > references, which quietens down the problem a little. >
The drawback with this is that it does not work under 5.8. Another way to handle this is to move the regular expression construction outside the init() subroutine entirely, since the regular expressions do not in fact depend on anything in the init() subroutine. This works under 5.008 _and_ 5.010. A patch to do it this way is attached. Tom Wyant
Download Regexp-Parser-Handlers.pat
application/octet-stream 1k

Message body not shown because it is not plain text.

I prettied up your patch a little and ported the solution to the Perl6::Rule::Parser module, which had exactly the same problem, but does not appear to be covered by the test cases. The updated patch is attached. Deven On Tue Jan 20 12:46:17 2009, WYANT wrote: Show quoted text
> On Fri Jan 02 05:44:38 2009, kentfredric@gmail.com wrote:
> > > > Attached is the same qr[] blocks re-written using perl5.10's named > > references, which quietens down the problem a little. > >
> > The drawback with this is that it does not work under 5.8. > > Another way to handle this is to move the regular expression > construction outside the init() subroutine entirely, since the regular > expressions do not in fact depend on anything in the init()
subroutine. Show quoted text
> This works under 5.008 _and_ 5.010. > > A patch to do it this way is attached. > > Tom Wyant
Subject: Regexp-Parser-0.20-nest.patch
# # https://rt.cpan.org/Public/Bug/Display.html?id=42096 # --- Regexp-Parser-0.20/lib/Regexp/Parser/Handlers.pm.orig 2004-07-06 09:38:26.000000000 -0400 +++ Regexp-Parser-0.20/lib/Regexp/Parser/Handlers.pm 2010-06-16 14:30:27.000000000 -0400 @@ -1,5 +1,9 @@ package Regexp::Parser; +my ($nest_eval, $nest_logical); +$nest_eval = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest_eval }) } )* ]x; +$nest_logical = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest_logical }) } )* ]x; + sub init { my ($self) = @_; @@ -696,9 +700,7 @@ # eval $self->add_handler('(?{' => sub { my ($S) = @_; - my $nest; - $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; - if (${&Rx} =~ m{ \G ($nest) \} \) }xgc) { + if (${&Rx} =~ m{ \G ($nest_eval) \} \) }xgc) { push @{ $S->{flags} }, &Rf; return $S->object(eval => $1); } @@ -721,9 +723,7 @@ # logical $self->add_handler('(??{' => sub { my ($S) = @_; - my $nest; - $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; - if (${&Rx} =~ m{ \G ($nest) \} \) }xgc) { + if (${&Rx} =~ m{ \G ($nest_logical) \} \) }xgc) { push @{ $S->{flags} }, &Rf; return $S->object(logical => $1); } --- Regexp-Parser-0.20/lib/Perl6/Rule/Parser.pm.orig 2005-05-25 19:14:15.000000000 -0400 +++ Regexp-Parser-0.20/lib/Perl6/Rule/Parser.pm 2010-06-16 14:31:11.000000000 -0400 @@ -3,6 +3,11 @@ use base 'Regexp::Parser'; +my ($nest_eval, $nest_logical); +$nest_eval = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest_eval }) } )* ]x; +$nest_logical = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest_logical }) } )* ]x; + + our $non_nest_brack = qr{ \[ [^]]* \] | { [^}]* } | @@ -905,9 +910,7 @@ # eval $self->add_handler('(?{' => sub { my ($S) = @_; - my $nest; - $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; - if (${&Rx} =~ m{ \G ($nest) \} \) }xgc) { + if (${&Rx} =~ m{ \G ($nest_eval) \} \) }xgc) { push @{ $S->{flags} }, &Rf; return $S->object(eval => $1); } @@ -930,9 +933,7 @@ # logical $self->add_handler('(??{' => sub { my ($S) = @_; - my $nest; - $nest = qr[ (?> [^\\{}]+ | \\. | { (??{ $nest }) } )* ]x; - if (${&Rx} =~ m{ \G ($nest) \} \) }xgc) { + if (${&Rx} =~ m{ \G ($nest_logical) \} \) }xgc) { push @{ $S->{flags} }, &Rf; return $S->object(logical => $1); }
This patch definitely quiets down 5.14
RT-Send-CC: kentfredric [...] gmail.com, wyant [...] cpan.org, deven [...] ties.org
This has been released to CPAN as a dev release 0.20_01. Will bump to 0.21 on Friday if no issues are found in CPAN testers.
RT-Send-CC: deven [...] ties.org, wyant [...] cpan.org
fixed in 0.20_01. 0.21 is on it's way to CPAN now.