Since the syntax is quite extensive, below, you will find the pseudo BNF. The special characters have the following meaning:
::= definition ( ) grouping if the parens are not quoted | separates alternatives '/' literal / (or any other character) CAPS a character or character sequence * preceding item can be repeated zero or more times ? preceding item can appear zero or one time + preceding item must appear one or more times
And the pseudo BNF describing the syntax is:
input ::= ( TEXT
| variable
| INDEX_OPEN input INDEX_CLOSE (loop_limits)?
)*
variable ::= DELIM_INIT (name|expression)
name ::= (NAME_CHARS)+
expression ::= DELIM_OPEN
(name|variable)+
(INDEX_OPEN num_exp INDEX_CLOSE)?
(':' command)*
DELIM_CLOSE
command ::= '-' (TEXT_EXP|variable)+
| '+' (TEXT_EXP|variable)+
| 'o' NUMBER ('-'|',') (NUMBER)?
| '#'
| '*' (TEXT_EXP|variable)+
| 's' '/' (TEXT_PATTERN)+
'/' (variable|TEXT_SUBST)*
'/' ('m'|'g'|'i'|'t')*
| 'y' '/' (variable|TEXT_SUBST)+
'/' (variable|TEXT_SUBST)*
'/'
| 'p' '/' NUMBER
'/' (variable|TEXT_SUBST)*
'/' ('r'|'l'|'c')
| '%' (name|variable)+
('(' (TEXT_ARGS)? ')')?
| 'l'
| 'u'
num_exp ::= operand
| operand ('+'|'-'|'*'|'/'|'%') num_exp
operand ::= ('+'|'-')? NUMBER
| INDEX_MARK
| '(' num_exp ')'
| variable
loop_limits ::= DELIM_OPEN
(num_exp)? ',' (num_exp)? (',' (num_exp)?)?
DELIM_CLOSE
NUMBER ::= ('0'|...|'9')+
TEXT_PATTERN::= (^('/'))+
TEXT_SUBST ::= (^(DELIM_INIT|'/'))+
TEXT_ARGS ::= (^(DELIM_INIT|')'))+
TEXT_EXP ::= (^(DELIM_INIT|DELIM_CLOSE|':'|'+'))+
TEXT ::= (^(DELIM_INIT|INDEX_OPEN|INDEX_CLOSE))+
DELIM_INIT ::= '$'
DELIM_OPEN ::= '{'
DELIM_CLOSE ::= '}'
INDEX_OPEN ::= '['
INDEX_CLOSE ::= ']'
INDEX_MARK ::= '#'
NAME_CHARS ::= 'a'|...|'z'|'A'|...|'Z'|'0'|...|'9'