Search documentation of Metastatic

# Metastatic.Adapters.Elixir.FromMeta (Metastatic v0.13.2)

View Source

Transform MetaAST (M2) back to Elixir AST (M1).

This module implements the reification function ρ_Elixir that instantiates meta-level representations back into Elixir-specific AST structures.

## New 3-Tuple Format

All MetaAST nodes are uniform 3-element tuples:

    {type_atom, keyword_meta, children_or_value}

Where:

- `type_atom` - Node type (e.g., `:literal`, `:binary_op`, `:function_def`)
- `keyword_meta` - Keyword list with metadata (line, subtype, operator, etc.)
- `children_or_value` - Value for leaf nodes, list of children for composites

## Transformation Strategy

Uses `Metastatic.AST.traverse/4` for bottom-up AST transformation:

1. Post-order traversal: Children are transformed before parents
2. Metadata extraction: Node attributes extracted from keyword metadata
3. Original metadata restoration: Uses `:original_meta` when available

## Examples

    iex> meta_ast = {:literal, [subtype: :integer], 42}
    iex> {:ok, elixir_ast} = FromMeta.transform(meta_ast, %{})
    iex> elixir_ast
    42

    iex> meta_ast = {:binary_op, [category: :arithmetic, operator: :+],
    ...>   [{:variable, [], "x"}, {:literal, [subtype: :integer], 5}]}
    iex> {:ok, elixir_ast} = FromMeta.transform(meta_ast, %{})
    iex> elixir_ast
    {:+, [], [{:x, [], nil}, 5]}

## Summary

### Functions

transform(meta_ast, metadata \\ %{})

Transform MetaAST back to Elixir AST.

## Functions

# transform(meta_ast, metadata \\ %{})

    @spec transform(term(), map()) :: {:ok, term()} | {:error, String.t()}

Transform MetaAST back to Elixir AST.

Returns `{:ok, elixir_ast}` on success or `{:error, reason}` on failure.

## Examples

    iex> FromMeta.transform({:literal, [subtype: :integer], 42}, %{})
    {:ok, 42}

    iex> FromMeta.transform({:variable, [], "x"}, %{context: Elixir})
    {:ok, {:x, [], Elixir}}