Skip to content

Extract

extract

Language-dispatching parse/extract entry points.

The public parse_file / extract_module_info in :mod:axm_ast.core.parser are the Python implementation (and the body of :class:PythonBackend). This module is the multi-language layer above them: it routes a path to the backend that owns its suffix, so callers that may see .py or .ts files use one entry point and never branch on language themselves.

For .py files this is byte-identical to calling parser directly (the registry returns the Python backend, which delegates to parser), so existing Python-only call paths are unaffected.

extract_calls(module, module_name=None)

Extract call-sites from module via the backend that owns its file.

Parameters:

Name Type Description Default
module ModuleInfo

A parsed :class:ModuleInfo (carries the source path).

required
module_name str | None

Dotted module name for CallSite.module (defaults to the file stem).

None

Returns:

Type Description
list[CallSite]

The module's call-sites in the language-agnostic model.

Raises:

Type Description
ValueError

If no backend is registered for the module's suffix.

Source code in packages/axm-ast/src/axm_ast/core/extract.py
Python
def extract_calls(module: ModuleInfo, module_name: str | None = None) -> list[CallSite]:
    """Extract call-sites from *module* via the backend that owns its file.

    Args:
        module: A parsed :class:`ModuleInfo` (carries the source path).
        module_name: Dotted module name for ``CallSite.module`` (defaults to the
            file stem).

    Returns:
        The module's call-sites in the language-agnostic model.

    Raises:
        ValueError: If no backend is registered for the module's suffix.
    """
    backend = backend_for(module.path)
    if backend is None:
        msg = f"Unsupported file type for call extraction: {module.path}"
        raise ValueError(msg)
    return backend.extract_calls(module, module_name=module_name)

extract_module(path)

Extract :class:ModuleInfo from path via its language backend.

Parameters:

Name Type Description Default
path Path

Source file in any supported language.

required

Returns:

Type Description
ModuleInfo

The language-agnostic :class:ModuleInfo for the file.

Raises:

Type Description
ValueError

If no backend is registered for the file's suffix.

FileNotFoundError

If the file does not exist.

Source code in packages/axm-ast/src/axm_ast/core/extract.py
Python
def extract_module(path: Path) -> ModuleInfo:
    """Extract :class:`ModuleInfo` from *path* via its language backend.

    Args:
        path: Source file in any supported language.

    Returns:
        The language-agnostic :class:`ModuleInfo` for the file.

    Raises:
        ValueError: If no backend is registered for the file's suffix.
        FileNotFoundError: If the file does not exist.
    """
    backend = backend_for(path)
    if backend is None:
        msg = f"Unsupported file type for AST extraction: {path}"
        raise ValueError(msg)
    return backend.extract_module(path)

parse_path(path)

Parse path with the backend that owns its suffix.

Parameters:

Name Type Description Default
path Path

Source file in any supported language (.py, .ts, …).

required

Returns:

Type Description
Tree

The parsed tree-sitter Tree.

Raises:

Type Description
ValueError

If no backend is registered for the file's suffix.

FileNotFoundError

If the file does not exist.

Source code in packages/axm-ast/src/axm_ast/core/extract.py
Python
def parse_path(path: Path) -> Tree:
    """Parse *path* with the backend that owns its suffix.

    Args:
        path: Source file in any supported language (``.py``, ``.ts``, …).

    Returns:
        The parsed tree-sitter ``Tree``.

    Raises:
        ValueError: If no backend is registered for the file's suffix.
        FileNotFoundError: If the file does not exist.
    """
    backend = backend_for(path)
    if backend is None:
        msg = f"Unsupported file type for AST parsing: {path}"
        raise ValueError(msg)
    return backend.parse_file(path)