ast_printer.l0

ast_printer.l0

Module: ast_printer

Source: compiler/stage2_l0/src/ast_printer.l0 Language: Dea/L0

Imports / Includes

  • parser
  • ast
  • std.vector
  • std.text
  • std.string
  • std.io

Symbols

Function ap_bool_str

1
func ap_bool_str(b: bool) -> string

Return “True” or “False” for a boolean value.

Parameters:

  • b: Boolean value.

Returns: String representation matching Python repr(bool) style.

Function ap_span_suffix

1
func ap_span_suffix(span: Span) -> string

Build a span-suffix annotation string @sl:sc-el:ec .

Parameters:

  • span: Source span.

Returns: Formatted span annotation.

Function ap_indent_str

1
func ap_indent_str(n: int) -> string

Build an indentation prefix string (2 spaces per level).

Parameters:

  • n: Indent level.

Returns: Indentation string.

Function ap_print_line

1
func ap_print_line(indent: int, text: string)

Print a line at the given indent level.

Parameters:

  • indent: Indent level (2 spaces each).
  • text: Text to print after the indentation.

Function ap_print_label

1
func ap_print_label(indent: int, name: string)

Print a child-field label at indent + 1 .

Parameters:

  • indent: Parent node indent level.
  • name: Label name without colon.

Function ap_quote_string

1
func ap_quote_string(s: string) -> string

Return a single-quoted escaped representation of a string.

Parameters:

  • s: String to quote.

Returns: Single-quoted escaped string.

Function ap_module_prefix

1
func ap_module_prefix(module_path: StringVector*?) -> string

Build the module qualifier prefix from an optional path vector.

For a module path [“std”, “io”] this returns “std.io::” . Returns “” when the path is null or empty.

Parameters:

  • module_path: Optional module path segments.

Returns: Formatted prefix ending with "::", or empty string.

Function ap_full_name

1
func ap_full_name(text_value: string, module_path: StringVector*?, name_qualifier: StringVector*?) -> string

Build the full qualified name for a variable reference or similar node.

Combines module_path, name_qualifier segments, and the local name into a display string like “std.io::SomeType” or “Enum::Variant” .

Parameters:

  • text_value: Base name.
  • module_path: Optional module path segments.
  • name_qualifier: Optional name qualifier segments.

Returns: Fully qualified display name.

Function ap_print_type_ref

1
func ap_print_type_ref(tr: TypeRef*, indent: int)

Print a type reference node.

Parameters:

  • tr: Type reference to print.
  • indent: Indent level.

Function ap_print_import

1
func ap_print_import(imp: Import*, indent: int)

Print an import node.

Parameters:

  • imp: Import to print.
  • indent: Indent level.

Function ap_print_param

1
func ap_print_param(p: Param*, indent: int)

Print a parameter node, including its type annotation.

Parameters:

  • p: Parameter to print.
  • indent: Indent level.

Function ap_print_field_decl

1
func ap_print_field_decl(fd: FieldDecl*, indent: int)

Print a field declaration node.

Parameters:

  • fd: Field declaration to print.
  • indent: Indent level.

Function ap_print_enum_variant

1
func ap_print_enum_variant(ev: EnumVariant*, indent: int)

Print an enum variant node, including any payload fields.

Parameters:

  • ev: Enum variant to print.
  • indent: Indent level.

Function ap_print_pattern

1
func ap_print_pattern(id: PatternId, pr: ParseResult*, indent: int)

Print a pattern node by arena id.

Parameters:

  • id: Pattern id in the arena.
  • pr: Parse result providing the pattern arena.
  • indent: Indent level.

Function ap_print_expr

1
func ap_print_expr(id: ExprId, pr: ParseResult*, indent: int)

Print an expression node by arena id.

Recursively prints child expressions and child type references.

Parameters:

  • id: Expression id in the arena.
  • pr: Parse result providing the expression arena.
  • indent: Indent level.

Function ap_print_stmt

1
func ap_print_stmt(id: StmtId, pr: ParseResult*, indent: int)

Print a statement node by arena id.

Recursively prints child statements, expressions, and patterns.

Parameters:

  • id: Statement id in the arena.
  • pr: Parse result providing all AST arenas.
  • indent: Indent level.

Function ap_print_func_decl

1
func ap_print_func_decl(fd: FuncDecl*, pr: ParseResult*, indent: int)

Print a function declaration including params, return type, and body.

Parameters:

  • fd: Function declaration to print.
  • pr: Parse result providing statement arenas.
  • indent: Indent level.

Function ap_print_struct_decl

1
func ap_print_struct_decl(sd: StructDecl*, indent: int)

Print a struct declaration including its fields.

Parameters:

  • sd: Struct declaration to print.
  • indent: Indent level.

Function ap_print_enum_decl

1
func ap_print_enum_decl(ed: EnumDecl*, indent: int)

Print an enum declaration including its variants.

Parameters:

  • ed: Enum declaration to print.
  • indent: Indent level.

Function ap_print_type_alias_decl

1
func ap_print_type_alias_decl(ta: TypeAliasDecl*, indent: int)

Print a type-alias declaration.

Parameters:

  • ta: Type-alias declaration to print.
  • indent: Indent level.

Function ap_print_let_decl

1
func ap_print_let_decl(ld: LetDecl*, pr: ParseResult*, indent: int)

Print a top-level let declaration.

Parameters:

  • ld: Let declaration to print.
  • pr: Parse result providing expression arenas.
  • indent: Indent level.

Function ap_print_top_level_decl

1
func ap_print_top_level_decl(tld: TopLevelDecl*, pr: ParseResult*, indent: int)

Dispatch to the correct per-kind declaration printer.

Parameters:

  • tld: Top-level declaration wrapper.
  • pr: Parse result providing all AST arenas.
  • indent: Indent level.

Function ap_print_module

1
func ap_print_module(mod: Module*, pr: ParseResult*)

Print the AST of a parsed module.

Mirrors the Stage 1 format_module() output contract:

  • Module header with scalar fields and span on one line.

  • imports: label and each Import child at indent 2.

  • decls: label and each top-level declaration at indent 2.

  • Empty imports or decls lists are omitted (no label printed).

Parameters:

  • mod: Module to print.
  • pr: Parse result providing all AST arenas (expr, stmt, pattern).