Search documentation of Metastatic

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

View Source

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

Implements the reification function ρ_Python that instantiates meta-level representations back into Python-specific AST structures.

## Transformation Strategy

The transformation reverses the abstraction performed by `ToMeta`, using metadata to restore Python-specific information when needed.

### M2.1 (Core Layer) → Python AST

- Literals, variables, operators, function calls, conditionals, blocks, early returns

### M2.2 (Extended Layer) → Python AST

- Loops: {:loop, :while, ...} → While, {:loop, :for_each, ...} → For
- Lambdas: {:lambda, params, captures, body} → Lambda
- Collection ops: {:collection_op, :map, ...} → ListComp or map() call
- Exception handling: {:exception_handling, ...} → Try

## Round-Trip Fidelity

The transformation aims for high fidelity:

- Metadata preserves line numbers and formatting hints
- Default values are provided when metadata is absent

## Summary

### Functions

transform(unknown, metadata)

Transform MetaAST back to Python AST.

## Functions

# transform(unknown, metadata)

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

Transform MetaAST back to Python AST.

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