This one had me stumpted. subrule(s /,/) is just a macro for <leftop: subrule /,/ subrule>, and so subrule(s? /,/) is just a macro for <leftop: subrule /,/ subrule>(?). However, internally, I think that leftop goes through another level, and so @arg must get overwritten. (that's just a guess as to what is happening, so don't take it as fact.) Anyways, whatever P::RD is doing internally, I would classify it as a bug.
However, just telling you that its a bug isn't really helping you, so here is a workaround:
my $parser = new Parse::RecDescent (q[ functiondefine: /function/i name "(" parameters[$item[1]](?) ")" " +{" name: /[A-Za-z][a-zA-Z0-9_]*/ parameters: parameter[$arg[0]] ',' parameters[$arg[0]] { [@ite +m[1,3]] } | parameter[$arg[0]] { [$item[1]] } parameter: name /as/i variabletype { [@item[1..$#item]] } variabletype: /variant|array|keyarray/i ]);
This is much more inefficent then using <leftop:> would be, but at least it works (at least as far as I've tested it.) I also collapsed your variabletype rule into a single regex, which will be much more efficient.
In reply to Re: Problem with Parse::RecDescent and subrule arguments
by jryan
in thread Problem with Parse::RecDescent and subrule arguments
by richard5mith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |