quivers.dsl.emit

AST → canonical .qvr source. Walks a Module and produces text that, when re-parsed by quivers.dsl.loads, compiles to the same program.

emit

AST -> .qvr source emit.

Walks a quivers.dsl.ast_nodes.Module and produces canonical .qvr source text under the homogenized surface (type / morphism / program / sample / observe / return / option-block / etc.).

The emit is a one-way printer, not a panproto ParseEmitLens: quivers' AST is already the resolved form. The printer's contract is semantic: the emitted source, re-parsed by quivers.dsl.loads, produces a Module that compiles to the same program as the original AST.

module_to_source

module_to_source(module: Module) -> str

Serialize a Module AST to canonical .qvr source.

Source code in src/quivers/dsl/emit.py
69
70
71
72
73
74
75
76
77
78
79
def module_to_source(module: Module) -> str:
    """Serialize a `Module` AST to canonical ``.qvr`` source."""
    parts: list[str] = []
    last_was_block = False
    for stmt in module.statements:
        emitted = _emit_statement(stmt)
        if last_was_block:
            parts.append("")
        parts.append(emitted)
        last_was_block = isinstance(stmt, ProgramDecl)
    return "\n".join(parts) + "\n"