drowzy / hxl

An Elixir implementation of HCL.
Apache License 2.0
30 stars 1 forks source link

impl Template sub language #2

Open drowzy opened 2 years ago

drowzy commented 2 years ago

Reference:

Within quoted and heredoc string expressions, the sequences ${ and %{ begin template sequences. Templates let you > directly embed expressions into a string literal, to dynamically construct strings from other values.

Template = (
    TemplateLiteral |
    TemplateInterpolation |
    TemplateDirective
)*
TemplateDirective = TemplateIf | TemplateFor;
TemplateInterpolation = ("${" | "${~") Expression ("}" | "~}";

TemplateIf = (
    ("%{" | "%{~") "if" Expression ("}" | "~}")
    Template
    (
        ("%{" | "%{~") "else" ("}" | "~}")
        Template
    )?
    ("%{" | "%{~") "endif" ("}" | "~}")
);

TemplateFor = (
    ("%{" | "%{~") "for" Identifier ("," Identifier) "in" Expression ("}" | "~}")
    Template
    ("%{" | "%{~") "endfor" ("}" | "~}")
);