View Source Alembic.Parser.Expression (alembic v0.1.0)
Parses the raw string content of a Liquid expression — everything that can
appear inside {{ ... }} output tags and {% if ... %} / {% for ... in ... %} conditions — into an Alembic.AST.expr() node.
Grammar (see docs/grammar.md):
expr = or_expr ;
or_expr = and_expr , { "or" , and_expr } ;
and_expr = not_expr , { "and" , not_expr } ;
not_expr = [ "not" ] , comparison ;
comparison = filtered_primary , [ compare_op , filtered_primary ] ;
filtered_primary = primary , { filter } ;
primary = variable | literal ;
filter = "|" , IDENT , [ ":" , expr , { "," , expr } ] ;Filters bind tighter than comparison and logical operators — this lets a
bare "name | upcase" parse on its own (used for output tags) while still
allowing filtered operands inside a condition, e.g. x | size > 0.
Summary
Functions
Parses the raw string content of an output tag or a tag condition into an
Alembic.AST.expr().
Types
Functions
@spec parse(String.t()) :: {:ok, Alembic.AST.expr()} | {:error, reason()}
Parses the raw string content of an output tag or a tag condition into an
Alembic.AST.expr().
Examples
iex> Alembic.Parser.Expression.parse("user.name")
{:ok, {:variable, ["user", "name"]}}
iex> Alembic.Parser.Expression.parse("name | upcase")
{:ok, {:filter_chain, {:variable, ["name"]}, [{:filter, "upcase", []}]}}
iex> Alembic.Parser.Expression.parse("x > 0 and not skip")
{:ok,
{:logical, :and, {:compare, :gt, {:variable, ["x"]}, {:literal, 0}},
{:not, {:variable, ["skip"]}}}}