Search documentation of Metastatic

# Metastatic.Adapters.Python.Subprocess (Metastatic v0.2.0)

View Source

Subprocess management for Python parser and unparser.

Handles communication with Python scripts via stdin/stdout with JSON serialization.

# Summary

## Functions

parse(source)

Parse Python source code to AST JSON.

unparse(ast)

Unparse AST JSON back to Python source code.

# Functions

# parse(source)

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

Parse Python source code to AST JSON.

## Examples

    iex> Metastatic.Adapters.Python.Subprocess.parse("x + 5")
    {:ok, %{"_type" => "Module", "body" => [...]}}

    iex> Metastatic.Adapters.Python.Subprocess.parse("x +")
    {:error, "SyntaxError: ..."}

# unparse(ast)

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

Unparse AST JSON back to Python source code.

## Examples

    iex> ast = %{"_type" => "Module", "body" => [...]}
    iex> Metastatic.Adapters.Python.Subprocess.unparse(ast)
    {:ok, "x + 5"}