drowzy / hxl

An Elixir implementation of HCL.
Apache License 2.0
30 stars 1 forks source link

Define a Evaluator behaviour and allow for defining custom evaluators during decode #5

Closed drowzy closed 3 years ago

drowzy commented 3 years ago

The evalution of the Ast is performed by HXL.Eval it does not expose the internal do_eval/2 functions which does the actual evaluation. Define a new behaviour HXL.Evaluator and provide a base implementation of HXL.Evaluator i.e the same functionality as in HXL.Eval. Allow for specifying a custom evaluator adapter in the decode/2 functions.

Something like:

defmodule HXL.Evaluator do
  defmodule Ctx do
    defstruct [:functions, :key_encoder, document: %{}, symbol_table: %{}]

    @type t :: %__MODULE__{
          document: map(),
          functions: map(),
          symbol_table: map(),
          key_encoder: (binary -> term())
        }
  end

  @callback eval(HXL.Ast.t(), Ctx.t()) :: Ctx.t() 
end

Ref #4