to<xxx> $x < $y </xxx>
<div class="code"> $x < $y </div>
I came up with the following grammar:
I wonder if I could solve this problem without that lookahead in the codetext. I mean I already said in the closecode what should be the end of the code. Or should I drop altogether the closecode tag ?my $grammar = q { entry: chunk(s) eodata { $item[1] } chunk: text | code text: m{[\w ]+} { qq(<div class="text">$item[1]</div>); } code: opencode codetext closecode {$item[2] } opencode: m{<xxx>} closecode: m{</xxx>} codetext: m{[\w <\$]+(?=</xxx>)} { qq(<div class="code">) . CGI::e +scapeHTML($item[1]) . qq(</div>); } eodata: m{^\Z} };
BTW it is not really xxx there but I could not keep the real word while posting on PerlMonks. Extra XP for those who can guess what do I have instead of xxx ;-)
Update:In the end the text parts will be able to contain some HTML markup and some special tags while the code parts will contain anything that can resemble some software source code. See the discussion about Web forum markup language and the Monastery
The exact nature of the special tags is not yet clear to me, though I am thinking about <<special_tag>>
In reply to Parse::RecDescent with lookahead or without ? by szabgab
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |