Metastatic.CLI.Translator
(Metastatic v0.10.4)
View Source
Cross-language translation orchestration for Metastatic CLI.
Handles translation of individual files or entire directories from one programming language to another using MetaAST as the intermediate representation.
Translation Pipeline
- Parse source code to native AST (M1)
- Transform to MetaAST (M2)
- Transform MetaAST to target language AST (M1')
- Unparse to target language source code
Example
iex> translate("example.py", :python, :elixir, "example.ex")
{:ok, "example.ex"}
Summary
Functions
Translate a single file from one language to another.
Translate a directory of files from one language to another.
Translate a single file, auto-detecting output path.
Types
Functions
@spec translate(file_path(), language(), language(), file_path()) :: translate_result()
Translate a single file from one language to another.
Parameters
source_path- Path to source filefrom_lang- Source language (:python,:elixir,:erlang)to_lang- Target language (:python,:elixir,:erlang)output_path- Path for output file
Examples
iex> translate("hello.py", :python, :elixir, "hello.ex")
{:ok, "hello.ex"}
iex> translate("invalid.py", :python, :elixir, "out.ex")
{:error, "Parse error: ..."}
@spec translate_directory(file_path(), language(), language(), file_path()) :: {:ok, [file_path()]} | {:error, String.t()}
Translate a directory of files from one language to another.
Recursively processes all files with matching extensions in the source directory and writes translated files to the output directory, preserving the directory structure.
Parameters
source_dir- Source directory pathfrom_lang- Source languageto_lang- Target languageoutput_dir- Output directory path
Examples
iex> translate_directory("src/python", :python, :elixir, "src/elixir")
{:ok, ["src/elixir/foo.ex", "src/elixir/bar.ex"]}
@spec translate_with_auto_output(file_path(), language(), language()) :: translate_result()
Translate a single file, auto-detecting output path.
Output path is generated by changing the file extension to match the target language.
Examples
iex> translate_with_auto_output("hello.py", :python, :elixir)
{:ok, "hello.ex"}
iex> translate_with_auto_output("src/foo.ex", :elixir, :python)
{:ok, "src/foo.py"}