Page Template Language -- help with the grammar !

java <javadesigner@yahoo.com>
25 Mar 2005 21:55:12 -0500

          From comp.compilers

Related articles
Page Template Language -- help with the grammar ! javadesigner@yahoo.com (java) (2005-03-25)
Re: Page Template Language -- help with the grammar ! nathan.moore@sdc.cox.net (Nathan Moore) (2005-03-27)
| List of all articles for this month |

From: java <javadesigner@yahoo.com>
Newsgroups: comp.compilers
Date: 25 Mar 2005 21:55:12 -0500
Organization: University of Pennsylvania
Keywords: parse, question
Posted-Date: 25 Mar 2005 21:55:12 EST

Folks:


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
ignored.


[.....] are expression sections. They are converted
into:


      out.println(.....)


everywhere they occur in the source (even within quoted
strings).


\[[ 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
as "["


Everything else is html text and is copied to the resulting
document verbatim.


For example:


================ Source ======================
<foo value="[fillin]">bar</foo>


"
some quoted text [[ code section ignored in string ]]
[expression-filledin-string]
"


[[ ...code ]]


\[[ foo ]]
\[ foo ]


===================== Result ========================
<foo value="out.print(fillin)">bar</foo>


"some quoted text [[ -- totally ignored ]]
out.print(filledin2)
"


...code....


[[
foo
]]


[ 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:


\[[text]]


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 ?


Best regards,
--j
[How come you want to reinvent php rather than using the one that
already exists? -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.