Expression.Eval (expression v2.41.4)

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

Return the default value for a potentially complex value.

Parses a given value into a number, being an integer or a float. If the given value is not able to be parsed, then it returns the raw value.

Functions

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.

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

handle_not_found(value)

not_founds_as_nil(other)

op(operator, a, b)

parse_number(value)

Parses a given value into a number, being an integer or a float. If the given value is not able to be parsed, then it returns the raw value.