Skip Menu |

This queue is for tickets about the Parse-RecDescent CPAN distribution.

Report information
The Basics
Id: 29966
Status: resolved
Priority: 0/
Queue: Parse-RecDescent

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

Bug Information
Severity: Normal
Broken in:
  • 1.94
  • v1.95.1
Fixed in: (no value)



Subject: regex with single backslash char not recognised
If you try to use this one-line grammar: whatever : /\\/ | /whatever/ you'll get the following error: Warning (line 1): Token pattern "m/\\/ | /" may not be a valid regular expression ERROR (line 1): Untranslatable item encountered: "/" (Hint: Set $::RD_HINT (or -RD_HINT if you're using "perl -s") for hints on fixing these problems.) but the first regex is obviously correct. If you're wondering how I discovered this, I'm trying to write an automatic translator for grammars written in ABNF into grammars for P::RD. Quoted strings in ABNF are case insensitive, so I'm translating quoted stuff into /whatever/i. The following workaround... works: whatever : /(?:\\)/ | /whatever/ I'm attaching the best test case script I managed to write (had to do weird redirection of STDERR to a pipe to make it work properly).
Subject: backslash.t
# vim: filetype=perl : use strict; use warnings; use Test::More tests => 1; # last test to print my ($grammar, $msg) = @_; pipe my($r, $w); open STDERR, '>&', $w; require Parse::RecDescent; my $parser = Parse::RecDescent->new('x: /\\\\/ | /x/'); print {$w} "STOPPED\n"; close $w; my $stderr; while (<$r>) { last if $_ eq "STOPPED\n"; $stderr .= $_; } is($stderr, undef, defined($msg) ? $msg : "grammar is ok");
From: mhhollomon [...] gmail.com
On Sat Oct 13 20:50:41 2007, POLETTIX wrote: Show quoted text
> If you try to use this one-line grammar: > > whatever : /\\/ | /whatever/ > > you'll get the following error: > > Warning (line 1): Token pattern "m/\\/ | /" may not be a valid regular > expression > > ERROR (line 1): Untranslatable item encountered: "/" > (Hint: Set $::RD_HINT (or -RD_HINT if you're using "perl -s") > for hints on fixing these problems.) > > but the first regex is obviously correct. >
Yea... three year old bug report... Change the definition of $TOKEN to: my $TOKEN = q{\G\s*/((\\\\/|[^/])*)/([cgimsox]*)}; The above is inspired by the single-quote example from "perldoc perlre"
It would seem that changing the definition of $TOKEN to: my $TOKEN = q{\G\s*/((\\\\/|\\\\\\\\|[^/])*)/([cgimsox]*)}; Would solve the issue. A slightly more readable version: my $TOKEN = qr!\G # start where last match left off \s* # skip whitespace / # start of regex-like pattern ( \\/ # matches '\/' in the string | \\\\ # matches '\\' in the string | [^/] # matches any other character except the delimiter )* / # end of regex like pattern ([cgimsox]*) # zero or more modifiers !x; I realize that this issue has been around fora long time. If you're still active and care to try this fix, I'd appeciate it. Until then, I've added it to a branch on my local repository. Thank you for the report and trouble-shooting! On Wed Nov 10 20:04:16 2010, markhh wrote: Show quoted text
> > Change the definition of $TOKEN to: > my $TOKEN = q{\G\s*/((\\\\/|[^/])*)/([cgimsox]*)}; > > The above is inspired by the single-quote example from "perldoc perlre"
I've gone ahead and merged this into the main branch. You can find the commit here: https://github.com/jtbraun/Parse-RecDescent/commit/3cd88a50853a00537470cc14c914fca36be3b4e1 Thank you again for reporting the bug!