-
Notifications
You must be signed in to change notification settings - Fork 0
Placeholder Definition
⚠️ ⚠️ THIS WIKI IS BEING USED TO JOT DOWN IDEAS AT PRESENT. DON'T ASSUME ANYTHING IS FIXED.⚠️ ⚠️
A Treacle place holder has the following form:
{{ source < arg1,arg2,argN > filter1 < arg1,arg2,argN > filterN < arg1,argN }}
or
{{ var := source < arg1,arg2,argN > filter1 < arg1,arg2,argN > filterN < arg1,argN }}
or
{{ var := source < arg1,arg2,argN > filter1 < arg1,arg2,argN > filterN < arg1,argN ; }}
Arguments (argX
) are optional. If they are omitted then the preceding <
must also be omitted. There is no limit to the number of arguments. Only @
command sources and filters take arguments. The number and type of arguments depends on the command or filter they are being used with. An argument is either given a literal value or it can take its value from a placeholder or a named variable.
There can be zero or more filters chained together. If there are no filters then the >
must be omitted. Filters transform the value piped in and the transformed value is piped out.
:=
is used to assign the value of the placeholder to var
. The order of execution is that source
is piped through any filters then the result is assigned to var
. The placeholder value is returned as normal unless a ;
is placed immediately before the closing }}
, which causes the placeholder to return Null. Hence ;
is really only of use when assigning a variable.
🗒️ Note that |
can be used in place of >
and :
can be used instead of <
to make placeholders look more like Liquid.
Here's the syntax definition in a BNF-like language.
<placeholder> ::= "{{" [ <assignment> ] <source> [ <modifier-chain> ] [ ";" ] "}}"
<assignment> ::= <variable> ":="
<source> ::= <variable> | <command> | <literal-value>
| <placeholder> | <special-variable>
<command> ::= <command-name> [ <args-group> ]
<command-name> ::= "@" <token>
<args-group> ::= <args-pipe> <args>
<args> ::= <arg> [ "," <args> ]
<arg> ::= <literal-value> | <placeholder> | <variable>
| <special-variable>
<modifier-chain> ::= <modifier-pipe> <modifier> [ <modifier-chain> ]
<modifier> ::= <filter> | <iterator> | <placeholder>
<filter> ::= <filter-name> [ <args-group> ]
<filter-name> ::= <token>
<iterator> ::= <iterator-name> [ <iterator-args> ] <modifier-chain>
<iterator-name> ::= "$" <token>
<iterator-args> ::= "(" <element-var> [ "," <accumulator-var>
[ ":=" <accumulator-init> ] ] ")"
<element-var> ::= <token>
<accumulator-var> ::= <token>
<accumulator-init> ::= <arg>
<variable> ::= <token> [ "[" <array-indices> "]" ]
<array-indices> ::= <array-index> [ "," <array-indices> ]
<array-index> ::= <integer> | <variable> | <placeholder>
<special-variable> ::= "%%" | "%@" | "%#" | "%_"
<token> ::= <letter> [ <token-body> ]
<token-body> ::= (<letter> | <digit> | "_" | "-") [ <token-body> ]
<literal-value> ::= <quoted-string> | <integer> | <float>
<integer> ::= [ <number-sign> ] <digits>
<float> ::= <integer> "." <digits> [ <exponent> ]
<exponent> ::= ( "e" | "E" ) <integer>
<number-sign> ::= "+" | "-"
<digits> ::= <digit> [ <digits> ]
<quoted-string> ::= <single-quoted-string> | <double-quoted-string>
<single-quoted-string> ::= <single-quote> [ <escaped-text> ] <single-quote>
<double-quoted-string> ::= <double-quote> [ <escaped-text> ] <double-quote>
<modifier-pipe> ::= ">" | "|"
<args-pipe> ::= "<" | ":"
<escaped-text> ::= (<non-escaping-char> | <escape-sequence>) [ <escaped-text> ]
<escape-sequence> ::= "\" <escaping-char>
<escaping-char> ::= "\" | <single-quote> | <double-quote> | "n" | "r" | "t"
<non-escaping-char> ::= Any Unicode character except an <escaping-char> or a
control character
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<single-quote> ::= U+0027
<double-quote> ::= U+0022