In case anyone wants to know what it would look like, a Parse::RecDescent parser would be something like this:
#!/usr/bin/perl -w use strict; use Parse::RecDescent; sub Parse::RecDescent::dispatch { my $self = shift(); my ($key, $value) = @_; print "$key: "; if ( ref($value) eq 'ARRAY' ) { print join(", ", @$value); } else { print $value; } print "\n"; } my $parser = new Parse::RecDescent << '__GRAMMAR__'; Pil: Title '{' NameTable Canvas Object(s) '}' /\Z/ Title: /^pageoutput-[^;]+;/ # the name-table NameTable: 'name-table' '{' NTLine(s) '}' NTLine: FileName FileType 'unix-filename' FileName FileName: '"' /[^"]+/ '"' FileType: 'atex-itf' | 'eps' # the canvas Canvas: 'canvas' '{' Data '}' { print "============================= CANVAS\n"; } # the objects Object: 'object' '{' Data '}' { print "============================= OBJECT\n"; } Data: KeyValue(s) KeyValue: Key Value { $thisparser->dispatch( $item[1], $item[2] ); } Key: /^\S+/ Value: '"' /[^"]+/ '"' { $item[2]; } | Number | '{' Array '}' { $item[2]; } Array: Number(s) | KeyValue(s) Number: /\d+/ __GRAMMAR__ undef $/; $parser->Pil(<STDIN>);
This is incomplete. What is left to do is to associate the various key/value pairs with their respective owners (either a 'canvas' or 'object'). If you try it out, note that an object's key/value pairs are printed before that object.
In reply to Re: Parsing a multiline data structure
by eg
in thread Parsing a multiline data structure
by HamNRye
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |