chahn has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use Parse::RecDescent; $::TestGrammar = <<'TG'; Output: PropLine(s) /\Z/ PropLine: CommentLine | SimpleProp | LastProp CommentLine: /\#.*\n/ { print "RULE: $item{__RULE__}\n"; print "MATCH: $item{__PATTERN1__}\n"; } SimpleProp: VAR EQ VAL ...LastProp { print "RULE: $item{__RULE__}\n" +; print "VAR: $item{VAR}\n"; print "EQ: $item{EQ}\n"; print "VAL: $item{VAL}\n\n"; } LastProp: VAR EQ VAL { print "RULE: $item{__RULE__}\n"; print "VAR: $item{VAR}\n"; print "EQ: $item{EQ}\n"; print "VAL: $item{VAL}\n\n"; } VAR: /[^=]+/ EQ: '=' VAL: /.*/ TG undef $/; my $foo = <>; my $parser = Parse::RecDescent->new($::TestGrammar); defined $parser->Output($foo) or die "FAILURE"; __END__ When I run this using this file: =================== # Comment Line # Comment #2 foo=this is property one but bar=does it grab this one too? baz=snark =================== I see this, as expected: =================== RULE: CommentLine MATCH: # Comment Line RULE: CommentLine MATCH: # Comment #2 RULE: SimpleProp VAR: foo EQ: = VAL: this is property one but RULE: SimpleProp VAR: bar EQ: = VAL: does it grab this one too? RULE: LastProp VAR: baz EQ: = VAL: snark =================== However, if I make one of the props multiline: =================== # Comment Line # Comment #2 foo=this is property one but bar=does it grab this one too? baz=snark =================== I see this: =================== RULE: CommentLine MATCH: # Comment Line RULE: CommentLine MATCH: # Comment #2 RULE: SimpleProp VAR: foo EQ: = VAL: this is property <----the rest of this VAL becomes part of the next VAR. no joy. RULE: SimpleProp VAR: one but bar EQ: = VAL: does it grab this one too? RULE: LastProp VAR: baz EQ: = VAL: snark ===================
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modifying Parse::RecDescent Grammar to deal with multiline property file entries
by suaveant (Parson) on Aug 15, 2007 at 20:33 UTC | |
by chahn (Beadle) on Aug 16, 2007 at 16:58 UTC | |
by suaveant (Parson) on Aug 16, 2007 at 17:21 UTC | |
|
Re: Modifying Parse::RecDescent Grammar to deal with multiline property file entries
by princepawn (Parson) on Aug 17, 2007 at 07:51 UTC |