ExSel v0.0.1 ExSel.Ast

Simple expression language AST

Link to this section Summary

Functions

Evaluates the passed ast and variables

Link to this section Types

Link to this type aexpr()
aexpr() :: vexpr_num() | vexpr_var() | aexpr_binop()
Link to this type aexpr_binop()
aexpr_binop() ::
  {:+, [aexpr()]} | {:-, [aexpr()]} | {:*, [aexpr()]} | {:/, [aexpr()]}
Link to this type bexpr()
bexpr() ::
  {:!, [bexpr()]}
  | {:&&, [bexpr()]}
  | {:||, [bexpr()]}
  | vexpr_bool()
  | vexpr_var()
  | cexpr()
Link to this type cexpr()
cexpr() :: cexpr_ord() | cexpr_eq()
Link to this type cexpr_eq()
cexpr_eq() ::
  {:==, [vexpr() | aexpr() | bexpr()]} | {:!=, [vexpr() | aexpr() | bexpr()]}
Link to this type cexpr_ord()
cexpr_ord() ::
  {:>, [aexpr()]} | {:<, [aexpr()]} | {:>=, [aexpr()]} | {:<=, [aexpr()]}
Link to this type eval_ctx()
eval_ctx() :: %{optional(binary()) => term()}
Link to this type eval_result()
eval_result() :: boolean() | binary() | number()
Link to this type t()
t() :: bexpr() | aexpr() | vexpr()
Link to this type vexpr_bool()
vexpr_bool() :: boolean()
Link to this type vexpr_num()
vexpr_num() :: number()
Link to this type vexpr_str()
vexpr_str() :: binary()
Link to this type vexpr_var()
vexpr_var() :: {:var, binary()}

Link to this section Functions

Link to this function eval!(ast, ctx \\ %{})
eval!(ast :: t(), ctx :: eval_ctx()) :: eval_result() | none()

Evaluates the passed ast and variables

Examples

iex> alias ExSel.Ast
iex> Ast.eval!(true, %{})
true
iex> Ast.eval!({:+,[1,{:var, "a"}]}, %{"a" => 1})
2
iex> Ast.eval!({:==,[1,1]}, %{})
true
iex> Ast.eval!({:/,[1,0]}, %{})
** (ArithmeticError) bad argument in arithmetic expression