in reply to RecDescent help needed!
This ignores and does not enforce the "data types" (agg, text N, int) in your markup language. But that would be easy to fix by changing the productions to:my $p = Parse::RecDescent->new( <<'END_GRAMMAR' ); parse: item(s) { "<ROOT>" . join("", @{$item[1]}) . "</R +OOT>" } item: /\w+/ /\([^\)]+\)=/ data { "<$item[1]>$item[3]</$item[1]>" } data: aggregate | string | integer aggregate: "(" item(s) ")" { join "", @{$item[2]} } string: /'([^']*)'/ { $1 } integer: /\d+/ { $item[1] } END_GRAMMAR undef $/; print $p->parse(<DATA>);
(and of course updating the semantic actions accordingly)item: /\w+/ "(agg)=" aggregate | /\w+/ "(text" /\d+/ ")=" string | /\w+/ "(int)=" int
Another thing to note is that in your input, there are two layers of "TITLE" tags, but your desired output has only one. You'd have to add a special-case productions to give your desired output (or post-process the XML output):
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RecDescent help needed!
by ikegami (Patriarch) on Feb 09, 2006 at 23:45 UTC | |
|
Re^2: RecDescent help needed!
by pklv (Initiate) on Feb 10, 2006 at 02:44 UTC |