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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.