I am trying to create a grammar and need some guidance. I've got it 'almost' working, but need help with the nested parsing. Below is what i've got so far, w/ the example of what to parse under __DATA__.
#!perl -w use strict; use Parse::RecDescent; $::RD_AUTOACTION = q { [@item[0..$#item]] }; my $grammar = q{ Document : Element(s) Element : Header Body Header : Element_Type Options(?) Element_Type: 'Q::' | 'T::' Options : '(' Arg(s) ')' Arg : /\b(\w+)\s*=\s*(\w+)\s*/xms Open_body : '{' Close_body : '}' Body : Open_body Line(s) Close_body <commit> Line : Element | Text | Text Line Text : /[\s\w]*[^\}]/xms }; my $survey_parser = Parse::RecDescent->new($grammar); undef $/; my $doc = <DATA>; my $tree = $survey_parser->Document($doc); die "no trees" if ! $tree; use Data::Dumper; print Dumper($tree); __DATA__ Q:: (arg1=val arg2=val) { Some text here T:: (arg=value) { Text here } Q:: (argn=etc) { T:: { optional args not included } } }
THX for any help!!!

2006-05-26 Retitled by Arunbear, as per Monastery guidelines
Original title: 'P::RD help'


In reply to nested parsing with Parse::RecDescent by loomis53

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.