Extension mechanism for jquery templates

Extension mechanism for jquery templates

I was looking at http://wiki.jqueryui.com/w/page/37898666/Template .  It seems a bit sparse right now.
I'm happy to spec out things like grammar based on the existing documentation but thought I'd post a strawman here.

The goals of this proposal are to:
(1) capture the existing grammar documented at  http://api.jquery.com/category/plugins/templates/
(2) propose a grammar that allows for custom user-defined extension tags
(3) enable user-defined pre-processor passes

Grammar

CompilationUnit ::== *( <TemplateElement> )
TemplateElement ::==
      <UnaryTemplateElement>
    | "{{" <UnaryTemplateName> "}}"
    | "{{" name=<BlockTemplateName> "}}" *( <TemplateElement> ) "{{/" name "}}"
    | "{{" <AnyTemplateName> "/}}"
    | <LiteralText>
    | <Interpolation>
LiteralText ::== * ( <LiteralTextChar> | <Escape> | /[${]/ (lookahead not in "{") )
Interpolation ::== "${" <Expression> "}"
Expression ::==  ε
    | "{" *( <Expression> ) "}" <Expression>
    | <String> <Expression>
    | <Comment> <Expression>
    | "/" (lookahead not in "*", "/")
    | /[^{}"'\/\\]|\\./ <Expression>
String ::== "\"" *( /[^"\\\r\n\u2028\u2029]|\\./ ) "\""
    |  "'" * ( /[^'\\\r\n\u2028\u2029]|\\./ ) "'"
Comment ::== "/*" *( /[^\*]/ | "*" (lookahead not in "/") ) "*/"
    | "//" *( /[^\r\n\u2028\u2029]/ )

So {{if}} would be a block element since it must be ended by an {{/if}} and {{else}} is a unary element name.
Extensions can registering new unary or block template names.

The expression is designed to simply match most javascript expressions with balanced curly brackets while allowing a parser to easily find the end of an interpolation without having to parse the full javascript grammar.  It may fail around curly brackets or quotes embedded in regular expression literals.  Regular expression literals should rarely appear in interpolations so this could be considered low risk.

If this looks ok, I can write this up in the wiki and post a proposal for an internal representation that allows custom pre-processing passes.

cheers,
mike