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

Report information
The Basics
Id:
129318
Status:
resolved
Priority:
Low/Low

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



Subject: Parse fails except when using debugger
The attached perl script defines a Regexp::Grammars grammar and checks some text against it. As is, with debugging off, it reports that there is no match. But when I turn debugging on (by uncommenting the "<debug:run>" statement), it reports that there is a match. I expected that with debugging turned on I'd be able to tell why no match was found with debugging turned off. I also attach the "perl -V" output, in perl-V.log.
Subject: parser-bug.pl
use Modern::Perl; use Regexp::Grammars; use YAML::Any qw(Dump); my $grammar = qr{ #<debug:run> <nocontext:> \A <statements> (?: \Z | <error: (?{ "Trailing text index $INDEX: '$CONTEXT'" })> ) <token: ws> (?: \s+ | \#[^\n]* )*+ <rule: statements> <[statement]>+ % [,] <rule: statement> <spec> : <fieldname> | \[ <count> \] \{ <statements> \} | <error:> <rule: count> <pptemplate> | \* <fieldname> | <funcname> \( <count> \) <rule: spec> <pptemplate> | <funcname> \( <spec> \) <token: fieldname> \w++ <token: funcname> \w++ <token: pptemplate> \w++ }s; my $input = <<EOD; N : count, [a(b(*count))] { square(N) : foo, # yes, foo! C3 : bar } # and bar, too EOD if ($input =~ $grammar) { print "Match:\n", Dump(\%/); } else { print "No match:\n ", join("\n ", @!); }
Subject: perl-V.log

Message body not shown because it is not plain text.

Added files with the output when not debugging, and the output when debugging.
Subject: output-with-debugging.txt

Message body is not shown because it is too large.

Subject: output-without-debugging.txt
No match: Trailing text index 9: ',' Expected statement, but found 'N : count,' instead
Subject: Re: [rt.cpan.org #129318] Parse fails except when using debugger
Date: Fri, 26 Apr 2019 22:46:51 +0000
To: bug-Regexp-Grammars@rt.cpan.org
From: Damian Conway <damian@conway.org>
Thanks for the report, Louis.

That was definitely a nasty Heisenbug,
and was an interesting challenge to track down and fix.

I've just uploaded a new version of Regexp::Grammars to CPAN (version 1.050),
which fixes the problem. It should propagate within the next 30 minutes or so.

BTW, to save you some time debugging the actual problem with your grammar,
the issue is that you're not allowing for the possibility of trailing whitespace
(e.g. comments) after the last <statement> in your input.

To fix it, you need either to change <rule: statements>:

     <rule: statements>
       <[statement]>+ % [,]
       <ws>  # Allow for trailing whitespace after last statement

or you need to change the top-level match:

     \A <statements>
     (?: <ws> \Z  # Allow for trailing whitespace after last statement
       | <error: (?{ "Trailing text index $INDEX: '$CONTEXT'" })>
     )

Thanks again for helping improve the module with this important bug report.

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.