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

Report information
The Basics
Id:
82763
Status:
open
Priority:
Low/Low

People
Owner:
Nobody in particular
Requestors:
TKEMMER [...] cpan.org
Cc:
AdminCc:

BugTracker
Severity:
Important
Broken in:
1.021
Fixed in:
(no value)



Subject: Regexp::Grammars: <minimize:> not working with <nocontext:>
Given the following Grammars fragment: <grammar: Expression> <nocontext:> <rule: Expression> <[expr=Expression1]>+ % <[ops=BinaryOp1]> <minimize:> [...] A single Expression1 will not be minimized with Regexp::Grammars v1.021. Looking into the code, the suspicious line is Grammars.pm:1024 if (1 == grep { $_ ne '!' && $_ ne '@' } keys %MATCH) { # ...single alnum key However, looking into %MATCH within that rule reveals the following keys: 'expr', '@', '!', '~' with '~' being referred to as the "context marker" in the code.
Apparently, this issue exists whether <nocontext:> has been specified or not, since %MATCH will always include a '~' key, set to 1 if <nocontext:> was specified, and set to 0 otherwise. Including '~' in the 'if' and the following 'delete' statement seems to fix this issue. BTW: making <minimize:> a "global" directive would be a nice addition.
Current work-around: using something like (?{ $MATCH = $MATCH{expr}->[0] unless exists $MATCH{ops} }) insteaf of <minimize:>
Subject: Re: [rt.cpan.org #82763] Regexp::Grammars: <minimize:> not working with <nocontext:>
Date: Tue, 22 Jan 2013 18:40:26 +1100
To: bug-Regexp-Grammars@rt.cpan.org
From: Damian Conway <damian@conway.org>
Many thanks for the bug report, Thomas, (and especially for the great detective work in locating the source of the problem). I *think* the patch I've applied and uploaded fixes the issue correctly. Please try the new version (1.022) and let me know if there are still any problems. Much appreciated, Damian
Damian, I could not find version 1.022 via the regular CPAN search. v1.021 is the latest version I can select. Is this an unofficial version hidden somewhere, so I cannot find it via search.cpan.org? Sorry if this is an FAQ, but until lately I was just a dumb, happy CPAN user, and this is my first bug report... Kind regards, Thomas
Subject: Re: [rt.cpan.org #82763] Regexp::Grammars: <minimize:> not working with <nocontext:>
Date: Wed, 30 Jan 2013 09:45:08 +1100
To: bug-Regexp-Grammars@rt.cpan.org
From: Damian Conway <damian@conway.org>
Hi Thomas, Sorry for the confusion about release 1.022. It was my fault entirely. (I fell foul of the changes to uploading when they moved the PAUSE server that feeds CPAN). I've just uploaded version 1.025, which has successfully appeared on CPAN: https://metacpan.org/module/DCONWAY/Regexp-Grammars-1.025/lib/Regexp/Grammars.pm Sorry for the mix-up. Damian
Hi Damian, I tried version 1.025 from CPAN, but without any luck. I've attached a small test script to further illustrate the issue. When I run the test script with v1.025, I get $VAR1 = { 'list' => { 'expr' => [ { 'item' => [ '1' ] } ] } }; whereas I would expect it to print $VAR1 = { 'list' => '1' }; I noticed the change in line 1024 (adding '~' to the filter expression), so I tinkered a little with the code, and changing Grammars.pm:1027 to delete @Regexp::Grammars::matches{'!', '@', '~'}; seems to do the trick. Don't know about side-effects, of course... Kind regards, and thanks for your efforts Thomas
Subject: regexp-grammars.t
#!/usr/bin/perl use Data::Dumper; use Regexp::Grammars; my $nocontext = qr{ <nocontext:> <list> <rule: list> <[expr]>+ % <[sep=([\w,;])]> <minimize:> <rule: expr> <[item]>+ % <[op=([+-])]> <minimize:> <token:item> (\d+) }xms; # if ("1+2,3" =~ $nocontext) { # print Dumper(\%/); # } else { # die "not matched\n"; # } if ("1" =~ $nocontext) { print Dumper(\%/); } else { die "not matched\n"; }
Subject: Re: [rt.cpan.org #82763] Regexp::Grammars: <minimize:> not working with <nocontext:>
Date: Thu, 31 Jan 2013 08:22:22 +1100
To: bug-Regexp-Grammars@rt.cpan.org
From: Damian Conway <damian@conway.org>
Hi again, Thomas. Apologies for the previously unsuccessful fix. The test file you sent really helped this time round! I've just uploaded version 1.026, which I believe *does* fix the problem. Give it a try and let me know. Damian
Hi Damian, AFAICS, 1.026 does indeed fix the problem. I tested with a grammar I'm currently working on (somewhat more complex than the one in my test script), and the result using <minimize:> is exactly the same as when I'm adding my hand-crafted workaround codeblocks. So thanks for your effort, and a big thank you for giving us this truly *awesome* module in the first place! Kind Regards, Thomas
Subject: Re: [rt.cpan.org #82763] Regexp::Grammars: <minimize:> not working with <nocontext:>
Date: Fri, 1 Feb 2013 09:07:49 +1100
To: bug-Regexp-Grammars@rt.cpan.org
From: Damian Conway <damian@conway.org>
Hi Thomas, I'm pleased to hear that I've finally solved it. Thanks so much for all your help. Damian


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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