Search documentation of Metastatic

# mix metastatic.translate (Metastatic v0.2.0)

View Source

Translate source code from one programming language to another using MetaAST.

## Usage

    mix metastatic.translate --from LANG --to LANG FILE [OPTIONS]
    mix metastatic.translate --from LANG --to LANG DIR --output OUT_DIR

## Arguments

- `FILE` or `DIR` - Source file or directory to translate

## Options

- `--from LANG` - Source language (python, elixir, erlang)
- `--to LANG` - Target language (python, elixir, erlang)
- `--output PATH` - Output file or directory (optional for single files)

## Examples

Translate a single Python file to Elixir (auto-detects output path):

    mix metastatic.translate --from python --to elixir hello.py
    # Creates: hello.ex

Translate with explicit output path:

    mix metastatic.translate --from python --to elixir hello.py --output lib/hello.ex

Translate an entire directory:

    mix metastatic.translate --from python --to elixir src/ --output lib/

Auto-detect source language from file extension:

    mix metastatic.translate --to elixir hello.py
    # Detects Python from .py extension

## Translation Process

1. Parse source code to language-specific AST (M1)
2. Transform to MetaAST (M2) - universal representation
3. Transform MetaAST to target language AST (M1')
4. Unparse to target language source code

## Limitations

- Some language-specific constructs may not translate perfectly
- Native layer (M2.3) constructs are preserved as language_specific nodes
- Comments and formatting may not be preserved
- Not all type annotations translate between languages