Subject: | Fwd: Errors using <MATCH=[rule]>+ construct |
Date: | Mon, 5 Sep 2016 13:15:21 +0200 |
To: | bug-Regexp-Grammars [...] rt.cpan.org |
From: | Felix Kuehnl <felix [...] bioinf.uni-leipzig.de> |
Hi,
I am getting error messages and parsing errors using the <MATCH=[Rule]>+
syntax within my grammar rules. I just started using this really cool
module, so I might just use it in a wrong way, but since it fails on a
documented example, I think I encountered a bug.
Under section "Defining a named grammar", a grammar for a list is given
like this (slightly modified to leave out the inheritance feature):
use v5.12;
use warnings;
my $test_grammar = do {
use Regexp::Grammars;
qr{
<List>
<rule: List>
<MATCH=[Item]>+ % <Separator>
<rule: Item>
\S++
<token: Separator>
\s* , \s*
}xms;
};
die "Parsing error" unless "asd" =~ $test_grammar;
Executing the code above with Regexp::Grammars 1.045 gives the following
output:
warn | Repeated subrule <MATCH=[Item]>+
| at /homes/brauerei2/felix/bin/regexp_grammar line 73
| will only capture its final match
| (Did you mean <[MATCH=[Item]]>+ instead?)
|
warn | Possible failed attempt to specify a subrule call:
| <MATCH=[Item]>
| near /homes/brauerei2/felix/bin/regexp_grammar line 72
| (If you meant to match literally, use: \<MATCH=[Item]>)
|
and the program dies with error "Parsing error". The problem is the
construct <MATCH=[Item]>+ of the List rule. Changing it into:
<rule: List>
# <MATCH=[Item]>+ % <Separator> # does not work
<[Item]>+ % <Separator>
<MATCH=(?{ $MATCH{Item} })>
. . . fixes the issue and does what I think the original example is
supposed to do: directly return the list of matched Items instead of a
result hash containing this list under key 'Item'. Now it would be
really nice to have the <MATCH=[Item]>+ shortcut, and since it is also
officially documented, I wondered why it isn't working? Thanks for your
help!
Regards,
Felix