z_expression (zotonic_core v1.0.0-rc.17)

Expression parsing and evaluation.

Summary

Functions

Evaluate a parsed expression tree.

Parse an expression to an expression tree. Uses the template_compiler parser.

Types

op/0

-type op() :: atom().

tree/0

-type tree() ::
          number() |
          binary() |
          {find_value, [tree()]} |
          {expr, op(), tree(), tree()} |
          {expr, op(), tree()} |
          {variable, binary()} |
          {attribute, atom(), tree()} |
          {index_value, tree(), tree()} |
          {apply_filter, atom(), atom(), tree(), [tree()]}.

Functions

eval(Tree, Vars, Context)

-spec eval(Tree, Vars, Context) -> Value
              when
                  Tree :: tree(),
                  Vars ::
                      proplists:proplist() |
                      #{binary() => term()} |
                      fun((binary()) -> term()) |
                      fun((binary(), z:context()) -> term()),
                  Context :: z:context(),
                  Value :: term().

Evaluate a parsed expression tree.

eval(Tree, Vars, Options, Context)

-spec eval(Tree, Vars, Options, Context) -> Value
              when
                  Tree :: tree(),
                  Vars ::
                      proplists:proplist() | #{binary() => term()} | fun((binary() | atom()) -> term()),
                  Options :: [Option],
                  Option ::
                      {filters_allowed, [atom()]} | {p, fun((term(), binary(), z:context()) -> term())},
                  Context :: z:context(),
                  Value :: term().

parse(Expr)

-spec parse(Expr) -> {ok, ParseTree} | {error, Reason}
               when Expr :: binary(), ParseTree :: tree(), Reason :: term().

Parse an expression to an expression tree. Uses the template_compiler parser.