l0_ast_printer.py

l0_ast_printer.py

Module: l0_ast_printer

Source: compiler/stage1_py/l0_ast_printer.py Language: Python

Symbols

Namespace l0_ast_printer

Function l0_ast_printer._format_span

1
str l0_ast_printer._format_span(Span|None span)

Format a source span for printing.

Parameters:

  • span: The source span to format, or None.

Returns: A string representation of the span (e.g., “ @1:1-2:1”), or an empty string if the span is None.

Function l0_ast_printer.format_node

1
List[str] l0_ast_printer.format_node(Any node, int indent=0)

Generic, reflection-based AST pretty-printer.

This function recursively traverses an AST node (or a list of nodes) and produces a human-readable string representation. It uses reflection to discover fields in dataclasses.

  • Shows the node class name.

  • Prints simple scalar fields inline (excluding span ).

  • Recursively prints child Node or list-of-Node fields on new indented lines.

  • Appends a concise span annotation when available.

Parameters:

  • node: The AST node, list of nodes, or other object to format.
  • indent: The current indentation level (number of 2-space increments).

Returns: A list of strings representing the formatted AST, one line per string.

Function l0_ast_printer.format_module

1
str l0_ast_printer.format_module(Module mod)

Convenience function to pretty-print a single Module as a string.

Parameters:

  • mod: The module to format.

Returns: A multiline string representing the formatted module.