Search documentation of Metastatic

# Metastatic.Adapters.Elixir.ToMeta (Metastatic v0.2.0)

View Source

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

This module implements the abstraction function α_Elixir that lifts Elixir-specific AST structures to the meta-level representation.

## Transformation Strategy

The transformation follows a pattern-matching approach, handling each Elixir AST construct and mapping it to the appropriate MetaAST node type.

### M2.1 (Core Layer)

- Literals: integers, floats, strings, booleans, nil, atoms
- Variables: single-identifier references
- Binary operators: arithmetic, comparison, boolean
- Unary operators: negation, logical not
- Function calls
- Conditionals: if/unless
- Blocks: multiple sequential expressions
- Early returns: (simulated via throw/catch in Elixir)

### M2.2 (Extended Layer)

- Anonymous functions (fn)
- Collection operations (Enum.map, filter, reduce)
- Pattern matching (case)
- List comprehensions (for)

### M2.3 (Native Layer)

- Pipe operator (|>)
- with expressions
- Macros (quote/unquote)

## Metadata Preservation

The transformation preserves M1-specific information in metadata:

- `:line` - line number from original source
- `:context` - variable context (Elixir, nil, module name)
- `:elixir_meta` - original Elixir metadata keyword list

This enables high-fidelity round-trips (M1 → M2 → M1).

# Summary

## Functions

transform(value)

Transform Elixir AST to MetaAST.

# Functions

# transform(value)

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

Transform Elixir AST to MetaAST.

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

## Examples

    iex> transform(42)
    {:ok, {:literal, :integer, 42}, %{}}

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

    iex> transform({:+, [], [{:x, [], Elixir}, 5]})
    {:ok, {:binary_op, :arithmetic, :+, {:variable, "x"}, {:literal, :integer, 5}}, %{}}