szabgab has asked for the wisdom of the Perl Monks concerning the following question:
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>>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse::RecDescent with lookahead or without ?
by ikegami (Patriarch) on Jan 22, 2005 at 17:43 UTC | |
by szabgab (Priest) on Jan 23, 2005 at 19:23 UTC | |
|
Re: Parse::RecDescent with lookahead or without ?
by dimar (Curate) on Jan 22, 2005 at 17:35 UTC | |
by szabgab (Priest) on Jan 23, 2005 at 19:18 UTC |