I've got a problem with Parse::RecDescent where it doesn't appear to be passing on subrule arguments. The grammar works fine otherwise, but the "parameter" rule does not seem to get any value for $arg[0], which should contain the name of the function matched in the "functiondefine" rule.

This is simplified example, but it is the basics of the problem...

use Parse::RecDescent; $grammar = << 'STOP'; functiondefine: /function/i name "(" parameter[ $item[2] ](s? /,/) +")" "{" name: /[A-Za-z][a-zA-Z0-9_]*/ parameter: name /as/i variabletype { warn $arg[0] } variabletype: /variant/i | /array/i | /keyarray/i STOP $parser = new Parse::RecDescent($grammar); $text = << 'STOP'; function myfunction(something as variant, somethingelse as array, foo +as keyarray) { } STOP $parser->functiondefine($text);

The result of which is...

Warning: something's wrong at (eval 15) line 168.
Warning: something's wrong at (eval 15) line 168.
Warning: something's wrong at (eval 15) line 168.

Meaning that $arg[0] isn't getting set.


In reply to 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.