Types of quotes for an HTML templating language

Posted by Ralph on Programmers See other posts from Programmers or by Ralph
Published on 2011-02-19T22:35:23Z Indexed on 2011/02/19 23:32 UTC
Read the original article Hit count: 432

I'm developing a templating language, and now I'm trying to decide on what I should do with quotes. I'm thinking about having 3 different types of quotes which are all handled differently:

                     backtick `     double quote "     single quote '
expand variables         ?              yes                 no
escape sequences        no              yes                  ?
escape html             no              yes                 yes

Backticks

Backticks are meant to be used for outputting JavaScript or unescaped HTML. It's often handy to be able to pass variables into JS, but it could also cause issues with things being treated as variables that shouldn't. My variables are PHP-style ($var) so I'm thinking that might mess with jQuery pretty bad... but if I disable variable expansion w/ backticks then, I'm not sure how would insert a variable into a JS code block?

Single Quotes

Not sure if escape sequences like \n should be treated as literals or converted. I find it pretty rare that I want to disable escape sequences, but if you do, you could use backticks. So I'm leaning towards "yes" for this one, but that would be contrary to how PHP does it.

Double Quotes

Pretty certain I want everything enabled for this one.

Modifiers

I'm also thinking about adding modifiers like @ or r in front of the string that would change some of these options to enable a few more combinations. I would need 9 different quotes or 3 quotes and 2 modifiers to get every combination wouldn't I?

My language also supports "filters" which can be applied against any "term" (number, variable, string) so you could always write something like

"blah blah $var blah"|expandvars

Or

"my string"|escapehtml

Thoughts? What would you prefer? What would be least confusing/most intuitive?

© Programmers or respective owner

Related posts about programming-languages

Related posts about strings