Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
There may or may not be any information between the opening and closing of a tag, but the presence of such tags is still important.
So far I have been able to build the following grammar for Parse::RecDescent:
File: Tag(s) EOF Tag: | MT Element EOT { print "MT: ", $item[1], "\n"; print " ", $item[2], "\n"; } | MT Element { print "MT: ", $item[1], "\n"; print " ", $item[2], "\n"; } | MT EOT { print "MT: ", $item[1], "\n"; } | MT { print "MT: ", $item[1], "\n"; } | <error> MT: /<MT\d+>/ Element: /[^\/\n]+/ EOF: /^\Z/ EOT: /\//
But the problem is that the Element token is too greedy and will eat up until the end of the line, swallowing any other tags. I have also tried to use the ...TOKEN construct within the grammar with no luck. What am I doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Difficulties defining a grammar for Parse::RecDescent
by Anonymous Monk on Jan 31, 2003 at 14:13 UTC | |
|
Re: Difficulties defining a grammar for Parse::RecDescent
by castaway (Parson) on Jan 31, 2003 at 14:17 UTC | |
|
Re: Difficulties defining a grammar for Parse::RecDescent
by Anonymous Monk on Jan 31, 2003 at 14:25 UTC | |
|
Re: Difficulties defining a grammar for Parse::RecDescent
by Jaap (Curate) on Jan 31, 2003 at 14:09 UTC |