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 ===================
In reply to Modifying Parse::RecDescent Grammar to deal with multiline property file entries by chahn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |