Hi, Please forgive me as I am rather new to the Parse::RecDescent module. I am working on a simple parser, which is rather easy to code using stand-alone perl, however I am trying to learn this powerful module. I am having trouble with my grammar and have looked at all the examples to help but to no avail. I basically want to be able to parse a structure similar to this:

dbSetCellPortTypes "/opt/mylib/95nm6M" "*" '( ("gnd!" "Inout" "Ground" ) ("vint!" "Inout" "Power" ) ) #f

Here is what I have so far:

use strict; use Parse::RecDescent; use Data::Dumper; $::RD_ERRORS = 1; $::RD_WARN = 1; $::RD_HINT = 1; $::RD_TRACE = 1; my $grammar = <<'_EOGRAMMAR_'; <autotree> QUOTED_STRING : /"/ <skip:""> quoted_char(s?) /"/ { " " . join "", @{$item[3]} # leading space flags a str +ing } quoted_char : /[^\\"]+/ | /\\n/ { "\n" } | /\\"/ { "\"" } portDefinition: "dbSetCellPortTypes" QUOTED_STRING QUOTED_STRIN +G portLists QUOTED_STRING portLists: "'" "(" list(s?) ")" list: "(" QUOTED_STRING ")" _EOGRAMMAR_ my $parse = Parse::RecDescent->new($grammar) or die "bad grammar"; undef $/; my $text = <<EOT; dbSetCellPortTypes "/opt/mylib/s956M" "*" '( ("gnd!" "Inout" "Ground" ) ("vint!" "Inout" "Power" ) ) #f EOT my $net = $parse->portDefinition($text) or die "bad netlist"; print Dumper[$net];

I am getting a bad netlist error and don't know how to debug from here. Any help is appreciated. Thanks, Frank


In reply to Help with Parse::RecDescent grammar by dramguy

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.