[antlr-interest] Trying to parsing CFML (ColdFusion)

Gaulin, Mark mgaulin at globalspec.com
Wed Feb 6 14:17:42 PST 2008


Hi Folks
I'm trying to write a parser for CFML (aka ColdFusion) and could use
some guidance.  CFML is a web scripting language where a .cfm page will
have a mix of html (or other "stuff") and CFML tags (which all start
with "<cf").  One of the ugliest part of the language (in terms of
parsing) is the built-in interpolation that can happen in the "html"
part.  Here's a simple example:
 
<cfset x = "Hello, world!">
    <html>
    <body>
<cfoutput>
        I say #x#<br>
        This is ##1.<br> <!--- shows "#1" --->
</cfoutput>
        This a #2. <!--- shows "#2" --->
    </body>
    </html>
 
 
The cfoutput tag processes all of the text between the open & close tag
and expands anything between hash symbols; two hash symbols are used to
escape to a single hash in the output. If there is no cfoutput "in
scope" then the hash symbol is just a hash symbol, and should not be
escaped.
 
Here's another fun part of the language... the hash can surround an
expression:
<cfoutput>
    #1+Max(2,3)# should be "4"
</cfoutput>
 
And string literals do interpolation too (so I guess they are not
literal), but in a stack-like way:
<cfset y = "I said #IIF(true, DE("yes"), DE("no"))#!">
Notice that the double quotes around "a" are just fine because the
hash-delimited interpolation part (#IIF(true, DE("yes"), DE("no"))#)
sort of takes precedence over the outer double-quoted string part.
 
Is this grammar (& lexer) possible with ANTLR?  For someone new to it?
It started to feel like this is a case of an "island grammar", but even
attempting to parse a "simple" quoted string (that can contain hashes)
all by itself is blowing my mind... the lexer is very very context
dependent.
 
Can anyone offer some advice?  I'm almost tempted to just write the
thing in straight java, but that feels lame (and tedious).
 
Thanks
    Mark
    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080206/934724b9/attachment.html 


More information about the antlr-interest mailing list