Skip to content

type_bridge.generator.parser

parser

TQL schema parser backed by the Rust type_bridge_core core.

parse_tql_schema

parse_tql_schema(schema_content)

Parse a TQL schema string into a :class:ParsedSchema.

Parsing runs entirely through the Rust type_bridge_core core. Annotations and docstrings (extracted from comments) are applied on the Python side.

Raises:

Type Description
RuntimeError

if the Rust core is unavailable (it is a default dependency, so this is a guard, not a fallback).

ValueError

if the Rust parser rejects the schema (propagated from core).

Source code in type_bridge/generator/parser.py
def parse_tql_schema(schema_content: str) -> ParsedSchema:
    """Parse a TQL schema string into a :class:`ParsedSchema`.

    Parsing runs entirely through the Rust ``type_bridge_core`` core. Annotations
    and docstrings (extracted from comments) are applied on the Python side.

    Raises:
        RuntimeError: if the Rust core is unavailable (it is a default dependency,
            so this is a guard, not a fallback).
        ValueError: if the Rust parser rejects the schema (propagated from core).
    """
    if not _RUST_SCHEMA_AVAILABLE or _RustTypeSchema is None:
        raise RuntimeError(
            "type_bridge_core is required to parse TQL schemas but is not "
            "available. Reinstall type-bridge with its native core."
        )

    entity_annots, attr_annots, rel_annots, role_annots = extract_annotations(schema_content)
    rust_schema = _RustTypeSchema.from_typeql(schema_content)
    return _rust_schema_to_parsed(rust_schema, entity_annots, attr_annots, rel_annots, role_annots)