As it seems you known what you're doing, I'll keep it short:

For the error directive to be helpful, you should commit between the keyword and the data, so the parser cannot backtrack out of it. This will force the location of the error to a position that can produce helpful error messages.

For comments it would help to handle whitespace in your grammer and disable automated whitespace handling. So you could define a nl as "ws* comment? nlchar" and comment as "'#' anychar_but_nlchar*". If you need inline comments, something like ws="(space|tab|comment2) ws?", comment2="'/*' anychar_but_nlchar* '*/'" would be the way to go.

"subnet_directive(s?)" allows all directives unlimited times. That is easy, and I would choose that approach, too, and check after the parsing for the number of directives. If you want to do it in the grammar, you need to recompose "subnet_directive", e.g. subnet_directive="repeatable_directive(s?) server? repeatable_directive(s?) keyfile? repeatable_directive(s?) default? repeatable_directive(s?) | repeatable_directive(s?) keyfile? repeatable_directive(s?) server? repeatable_directive(s?) default? repeatable_directive(s?) | repeatable_directive(s?) default? repeatable_directive(s?) keyfile? repeatable_directive(s?) server? repeatable_directive(s?) | repeatable_directive(s?) default? repeatable_directive(s?) server? repeatable_directive(s?) keyfile? repeatable_directive(s?)". Or, and that's a little bit easier, you modify the attached Perl code to reject being run twice---analyze the existing data structure if the value is already there...


Search, Ask, Know

In reply to Re: Parse::RecDescent - some questions by Beechbone
in thread Parse::RecDescent - some questions by ribasushi

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.