I am having a problem with defining a grammar for
Parse::RecDescent - The format which I am parsing is relative simple and consists of a textfile with opening tags defined as
<MT\d+> (for example,
<MT100> or
<MT57>). These tags may be closed by one of two events:
- encountering a slash, </code>/</code>, or newline, \n, or
- encountering another opening tag
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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.