Formal BNF for email templates

Following is the formal Backus Naur Form (BNF) for the email templates.

<start>
::=
( <template-inst> )*
<template-inst>
::=
|

'{$'[ <template-elem> ] '}'
'<$'
[ <template-elem> ] '>'

<template-elem>
::=
|
|
<expr>
<command>
<pe-compat>
<expr>
::=
<factor> ( <selector> | <modifier> )*
<factor>
::=
|
|
|
|

<string>
<triple-quoted-string>
<num>
<id 1>
<container-literal>

<selector>
::=
|
|

'.' <id 2>
'.' <num>
'['<expr> ']'

<modifier>
::=
<id 3>[<args-with-parens>]
<args-with-parens>
::=
'(' [ <arg-list> ] ')'
<arg-list>
::=
<arg> [ ',' <arg-list> ]
<container-literal>
::=
'[' <list-list> | <map-list> ']'
<list-list>
::=
[ <expr> ( ',' <expr> )* ]
<map-list>
::=
|
<key-value-pairs> [ ',' ':' <expr> ]
':' [ <expr> ]
<key-value-pairs>
::=
<expr> ':' <expr> ( ',' <expr> ':' <expr> )*
<command>
::=
|
<id 4> [ <arg-list> ]
<id 4> <args-with-parens>
<string>
::=
|
'"'characters '"'
"'" characters "'"
(nested instructions expanded and
escapes: \t, \r, \n, \\, \', \", \xHH, \uHHHH)
<triple-quoted-string>
::=
|

' " " " 'characters ' " " " '
" ' ' ' " characters " ' ' ' "
(no nested instruction expansions or escapes)

<id>
::=
[a-zA-Z_] [a-zA-Z_0-9]*
<num>
::=
[0-9]+
 

Process Engine Compatibility BNF

<pe-compat>
::=
|
( 'f_' or 'F_' ) <id 5> [ <pe-arg] >
( 'f_' or 'F_' )<id 5> [ <pe-format] >
<pe-arg>
::=
<u-string>
<pe-format>
::=
'[' <num> ']'
<u-string>
::=
everything up to the template’s lead-out

Notes

id 1 <parameter-ref> identifiers use the template parameter namespace.

id 2 <selector> identifiers use the key/property/field namespace, which depends on the object being referenced.

id 3 <modifier> identifiers use the modifier namespace.

id 4 <command> identifiers use the command namespace, but only if not found first in the template parameter namespace.

Id 5 <pe-compat> identifiers are TBD, but will include the set (at least) of the ones currently used by Process Engine.

Comments may be enclosed by /* */ and // and are treated as whitespace and do not appear in this BNF.