Metastatic.Supplemental.Transformer
(Metastatic v0.10.4)
View Source
Helper module for transforming MetaAST using registered supplementals.
Coordinates between the registry and supplemental modules to perform transformations on constructs that don't have native language support.
Summary
Functions
Checks if a supplemental is available for the given construct and language.
Lists all supplemental-supported constructs for a language.
Attempts to transform a MetaAST construct using a registered supplemental.
Attempts to transform, raising an exception if no supplemental is available.
Functions
Checks if a supplemental is available for the given construct and language.
Examples
iex> Transformer.available?(:actor_call, :python)
true
iex> Transformer.available?(:unsupported_construct, :python)
false
Lists all supplemental-supported constructs for a language.
Examples
iex> Transformer.supported_constructs(:python)
[:actor_call, :actor_cast, :spawn_actor]
@spec transform(term(), atom(), map()) :: {:ok, term()} | :error | {:error, Exception.t()}
Attempts to transform a MetaAST construct using a registered supplemental.
Looks up the appropriate supplemental module for the given language and construct, then delegates transformation to that module.
Returns:
{:ok, transformed}- Successfully transformed by supplemental:error- No supplemental handles this construct{:error, exception}- Transformation failed
Examples
iex> Transformer.transform({:actor_call, actor, msg, timeout}, :python, %{})
{:ok, python_ast}
iex> Transformer.transform({:unsupported_construct, val}, :python, %{})
:error
Attempts to transform, raising an exception if no supplemental is available.
Similar to transform/3 but raises MissingSupplementalError when no
supplemental handles the construct.
Examples
iex> Transformer.transform!({:actor_call, actor, msg, timeout}, :python, %{})
{:ok, python_ast}
iex> Transformer.transform!({:unsupported_construct, val}, :python, %{})
** (Metastatic.Supplemental.Error.MissingSupplementalError)