You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The package can be installed by adding ex_pression to your list of dependencies in mix.exs:
defdepsdo[{:ex_pression,"~> 0.5.0"}]end
Key features
Safe evaluation without access to other Elixir modules.
iex>ExPression.eval("exit(self())"){:error,%ExPression.Error{name: "UndefinedFunctionError",message: "Function 'self/0' was referenced, but was not defined",data: %{function: :self}}}
Extend expressions by providing Elixir module with functions that you want to use.
defmoduleMyFunctionsdo# use $ special symbol in expressionsdefhandle_special("$",date_str),do: Date.from_iso8601!(date_str)# Use diff function in expressionsdefdiff(date_1,date_2),do: Date.diff(date_1,date_2)endiex>ExPression.eval(~s/diff($"2023-02-02", $"2022-02-02")/,functions_module: MyFunctions){:ok,365}
String representation of expression is parsed into AST form. Parsing is done with PEG grammar parser xpeg. Grammar is defined in module ExPression.Parser.Grammar.
AST interpretation logic is written in plain Elixir in module ExPression.Interpreter.
Contribution
Feel free to make a pull request. All contributions are appreciated!