Expression.Eval (expression v2.3.1)

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!/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]

Link to this section Summary

Link to this section Functions

Link to this function

decimal_op(operator, a, b)

Link to this function

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

Link to this function

not_founds_as_nil(other)

Link to this function

op(operator, a, b)