Search documentation of Metastatic

# Metastatic.Supplemental.Transformer (Metastatic v0.13.2)

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

available?(construct, language)

Checks if a supplemental is available for the given construct and language.

supported_constructs(language)

Lists all supplemental-supported constructs for a language.

transform(meta_ast, language, metadata)

Attempts to transform a MetaAST construct using a registered supplemental.

transform!(meta_ast, language, metadata)

Attempts to transform, raising an exception if no supplemental is available.

## Functions

# available?(construct, language)

    @spec available?(atom(), atom()) :: boolean()

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

# supported_constructs(language)

    @spec supported_constructs(atom()) :: [atom()]

Lists all supplemental-supported constructs for a language.

## Examples

    iex> Transformer.supported_constructs(:python)
    [:actor_call, :actor_cast, :spawn_actor]

# transform(meta_ast, language, metadata)

    @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

# transform!(meta_ast, language, metadata)

    @spec transform!(term(), atom(), map()) :: {:ok, term()} | no_return()

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)