TStanley has asked for the wisdom of the Perl Monks concerning the following question:
The output from this is:#!/opt/perl5/bin/perl -w use strict; use Parse::RecDescent; use vars qw ($grammar); $::RD_AUTOACTION=q{print"$item[0]: @item[1..$#item]\n"; 1}; $grammar = q( file: section(s) section: header assign(s?) header: '[' /\w+/ ']' assign: /\w+/ '=' /\w+/ | /\w+/ '=' /\w+/ '' /\s+[\;#]/ /\w+$/ ); my $parser= Parse::RecDescent->new($grammar); my $text; { $/=undef; $text=<DATA>; } my $tree=$parser->file($text); __DATA__ [Section1] key1 = value1 #Comment key2 = value2 ;Comment key3 = value3 [Section2] key4 = value4 key5 = value5
By printing out $#item in the $::RD_AUTOACTION, I was able to see that it was totally ignoring anything past the value.header: [ Section1 ] assign: key1 = value1 section: 1 ARRAY(0x401da6cc) file: ARRAY(0x401da708)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with P::RD grammar
by artist (Parson) on May 23, 2003 at 19:00 UTC |