mix metastatic.translate
(Metastatic v0.10.4)
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_DIRArguments
FILEorDIR- 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.exTranslate with explicit output path:
mix metastatic.translate --from python --to elixir hello.py --output lib/hello.exTranslate 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 extensionTranslation Process
- Parse source code to language-specific AST (M1)
- Transform to MetaAST (M2) - universal representation
- Transform MetaAST to target language AST (M1')
- 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