Expression.Eval (expression v2.33.0)

Expression.Eval is responsible for taking an abstract syntax tree (AST) as generated by Expression.Parser and evaluating it.

At a high level, an AST consists of a Keyword list with two top-level keys, either :text or :expression.

Expression.Eval.eval!/3 will return the output for each entry in the Keyword list. :text entries are returned as regular strings. :expression entries are returned as typed values.

The returned value is a list containing each.

Example

iex(1)> Expression.Eval.eval!([text: "hello"], %{})
["hello"]
iex(2)> Expression.Eval.eval!([text: "hello", expression: [literal: 1]], %{})
["hello", 1]
iex(3)> Expression.Eval.eval!([
...(3)>   text: "hello",
...(3)>   expression: [literal: 1],
...(3)>   text: "ok",
...(3)>   expression: [literal: true]
...(3)> ], %{})
["hello", 1, "ok", true]

Summary

Functions

Link to this function

default_value(val, opts \\ [])

Return the default value for a potentially complex value.

Complex values can be Maps that have a __value__ key, if that's returned then we can to use the __value__ value when eval'ing against operators or functions.

Link to this function

eval!(ast, context, mod \\ Expression.Callbacks)

Link to this function

handle_not_found(value)

Link to this function

not_founds_as_nil(other)

Link to this function

op(operator, a, b)