Skip Menu |

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

Report information
The Basics
Id: 66767
Status: open
Priority: 0/
Queue: Regexp-Grammars

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

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



Subject: LaTeX example requires space in front of a command
I tried the example rule set for simple LaTeX parsing: my $parser = qr{ <File> <rule: File> <[Element]>* <rule: Element> <Command> | <Literal> <rule: Command> \\ <Literal> <Options>? <Args>? <rule: Options> \[ <[Option]> ** (,) \] <rule: Args> \{ <[Element]>* \} <rule: Option> [^][\$&%#_{}~^\s,]+ <rule: Literal> [^][\$&%#_{}~^\s]+ }xms; It doesn't work on a string like '\ref{A}-\ref{B}'. According to my understanding, this should be parsed into a command '\ref{A}', a literal '-' and another command '\ref{B}'. However, Regexp::Grammars seems not to be able to split '-\ref{B}' and chokes. It works correctly if I insert a space: '\ref{A}- \ref{B}', but according to the rules, this should not be necessary. My test script together with its output are attached. Thanks for Regexp::Grammars and best wishes Lutz
Subject: regexp_grammars_bug.pl
#!/usr/bin/perl use strict; use warnings; use Regexp::Grammars; use Data::Dumper; $Data::Dumper::Maxdepth = 4; my $parser = qr{ <File> <rule: File> <[Element]>* <rule: Element> <Command> | <Literal> <rule: Command> \\ <Literal> <Options>? <Args>? <rule: Options> \[ <[Option]> ** (,) \] <rule: Args> \{ <[Element]>* \} <rule: Option> [^][\$&%#_{}~^\s,]+ <rule: Literal> [^][\$&%#_{}~^\s]+ }xms; '\ref{A}-\ref{B}' =~ $parser; print Dumper(\%/); '\ref{A}- \ref{B}' =~ $parser; print Dumper(\%/); __END__ # the output I get is this: $VAR1 = { '' => '\\ref{A}-\\ref', 'File' => { '' => '\\ref{A}-\\ref', 'Element' => [ { '' => '\\ref{A}', 'Command' => 'HASH(0x849d354)' }, { '' => '-\\ref', 'Literal' => '-\\ref' } ] } }; $VAR1 = { '' => '\\ref{A}- \\ref{B}', 'File' => { '' => '\\ref{A}- \\ref{B}', 'Element' => [ { '' => '\\ref{A}', 'Command' => 'HASH(0x849d4a4)' }, { '' => '-', 'Literal' => '-' }, { '' => ' \\ref{B}', 'Command' => 'HASH(0x847abf4)' } ] } };
Subject: Re: [rt.cpan.org #66767] LaTeX example requires space in front of a command
Date: Fri, 1 Apr 2011 08:43:27 +1100
To: bug-Regexp-Grammars [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Lutz, Many thanks for the bug report. The grammar is obviously not handling literals correctly. Changing the Literal rule to:       <rule: Literal>    [^][\\\$&%#_{}~^\s]+ fixes the problem. I have now updated this in the distribution. All the best, Damian