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 *.
/\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.What is the /\Z/ doing actually?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Help with Parse::RecDescent grammar
by dramguy (Novice) on Dec 13, 2006 at 17:29 UTC | |
by ikegami (Patriarch) on Dec 13, 2006 at 17:46 UTC |