in reply to Re^6: Help with Parse::RecDescent grammar
in thread Help with Parse::RecDescent grammar

The #f is a boolean value

ah!

my $grammar = <<'_EOGRAMMAR_'; { # These apply to code in those block and all actions. use strict; use warnings; my %escapes = ( n => "\n", ); sub dequote_double { for (my $s = @_ ? $_[0] : $_) { s/^"//g; s/"$//g; s/\\(.)/$escapes{$1} || $1/eg; return $_; } } } parse : portDef(s?) /\Z/ { $item[1] } portDef : "dbSetCellPortTypes" QSTRING QSTRING portList BOOL { [ @item[1..5] ] } portList : "'" "(" record(s?) ")" { $item[3] } record : "(" QSTRING(s?) ")" { $item[2] } QSTRING : /"(?:[^"\\]|\\.)*"/ { dequote_double($item[1]) } BOOL : /#[tf]\b/ _EOGRAMMAR_

One thing I notice is when I try to parse multiple entries, I get the bad netlist error again.

Copy and paste error. There was a missing *.

What is the /\Z/ doing actually?

/\Z/ means makes sure we're at end of file. Without it, extra garbage at the end will just get ignored. It's worst that it sounds, because anything the parser doesn't understand is garbage, includes malformed dbSetCellPortTypes records. If there were a syntax error halfway through the file, you'd silently ignore everything after the syntax error if the /\Z/ is missing.

Replies are listed 'Best First'.
Re^8: Help with Parse::RecDescent grammar
by dramguy (Novice) on Dec 13, 2006 at 17:29 UTC
    Ahh, Ok, I think Im starting to understand how this module works.

    One more question though. Im trying to skip all lines which begin with a ";" as this is a comment. I used the following code to no avail:

    <skip:';'>

    Am I missing something here?

    Thanks

    F

      parse : <skip:'(?:\s+|;[^\n]*\n)*'> portDef(s?) /\Z/ { $item[2] }