Skip to content

Registry

registry

Language-backend registry — auto-detects a file's backend by extension.

The registry is the single dispatch point: backend_for(path) returns the :class:LanguageBackend that owns the file's suffix, or None for an unsupported extension. supported_suffixes() powers file discovery so the analyzer collects every language's files, not just .py.

The Python backend is always registered. Optional backends (TypeScript, Svelte) register themselves on first import iff their optional tree-sitter grammar is installed (axm-ast[typescript]), mirroring axm-echo's lazy-torch convention.

backend_for(path)

Return the backend that owns path by its suffix, or None.

Source code in packages/axm-ast/src/axm_ast/core/backends/registry.py
Python
def backend_for(path: Path) -> LanguageBackend | None:
    """Return the backend that owns *path* by its suffix, or ``None``."""
    return get_backend(path.suffix)

get_backend(suffix)

Return the backend registered for suffix, or None if unsupported.

Source code in packages/axm-ast/src/axm_ast/core/backends/registry.py
Python
def get_backend(suffix: str) -> LanguageBackend | None:
    """Return the backend registered for *suffix*, or ``None`` if unsupported."""
    _ensure_default_backends()
    return _REGISTRY.get(suffix)

register_backend(backend)

Register backend for each of its suffixes (idempotent, last wins).

Source code in packages/axm-ast/src/axm_ast/core/backends/registry.py
Python
def register_backend(backend: LanguageBackend) -> None:
    """Register *backend* for each of its suffixes (idempotent, last wins)."""
    for suffix in backend.suffixes:
        _REGISTRY[suffix] = backend

supported_suffixes()

Return every registered file suffix (used for multi-language discovery).

Source code in packages/axm-ast/src/axm_ast/core/backends/registry.py
Python
def supported_suffixes() -> frozenset[str]:
    """Return every registered file suffix (used for multi-language discovery)."""
    _ensure_default_backends()
    return frozenset(_REGISTRY)