|Page Template Language -- help with the grammar ! email@example.com (java) (2005-03-25)|
|Re: Page Template Language -- help with the grammar ! firstname.lastname@example.org (Nathan Moore) (2005-03-27)|
|Date:||25 Mar 2005 21:55:12 -0500|
|Organization:||University of Pennsylvania|
|Posted-Date:||25 Mar 2005 21:55:12 EST|
I'm trying to write a server side page templating thingy.
Here's what I would like to do, syntax wise:
[[....]] are code sections.
Code sections are copied to the resulting document verbatim.
If code sections appear within quoted strings, they are
[.....] are expression sections. They are converted
everywhere they occur in the source (even within quoted
\[[ escapes the code section. \[[ prevents a code section
from starting and is copied to the resulting document as "[["
\[ escapes the expression section. \[ does not start a
expression section and is copied to the resulting document
Everything else is html text and is copied to the resulting
================ Source ======================
some quoted text [[ code section ignored in string ]]
[[ ...code ]]
\[[ foo ]]
\[ foo ]
===================== Result ========================
"some quoted text [[ -- totally ignored ]]
[ foo ]
Trying to write a grammar/lexer for this is proving
to a be a bit tricky. This is because:
a) [ and [[ have a common prefix "["
b) \[ and \[[ are both valid escape sequences. However,
if I have:
I want to ignore the entire line, not treat that as:
--> \[ [text] ] --> \[ out.print(text) ]
So far I've come up with:
text -> html* | exp* | code*
html -> all chars
exp -> '[' exptext ']'
code -> '[[' codetext ']]'
codetext -> (any char)*
exptext -> (any char)*
But I want to specify that \[ does not start an exp
and \[[ does not start code. How to do that in the grammar ?
I also want to specify that \] does not end an exp
and \]] does not end code. How to do that in the grammar ?
[How come you want to reinvent php rather than using the one that
already exists? -John]
Return to the
Search the comp.compilers archives again.