Skip to main content

Module pprint

Module pprint 

Source
Expand description

AST → .polydat source pretty-printer.

Used by the subscope synthesizer (SRD-13f §“Wire-reference classification”) to re-emit retained AST statements pulled from a parent program’s binding_ast_for into a child scope’s source-text input. The pretty-printer is the bridge between AST-as-metadata (canonical) and the current string-based synthesizer pipeline. A direct AST-mode compile path is the eventual end state, but until then the synthesizer needs a faithful AST → source round-trip.

§Round-trip contract

For every Statement/Expr produced by the parser, pp_statement / pp_expr produces source text that re-parses into a semantically equivalent AST. “Semantically equivalent” means same node types and identical inner data (modulo Spans, which capture parser position and are not preserved across re-parse).

§Precedence and parens

BinOp expressions are emitted with parens around the whole expression. This is uniformly safe — re-parsing produces the same tree structure — at the cost of extra parens. The synthesizer’s output is not user-facing; legibility is not a concern.

Functions§

pp_expr
Pretty-print an expression. Always emits parens around BinOp for round-trip safety.
pp_file
Pretty-print a full file: every statement, separated by newlines.
pp_statement
Pretty-print a top-level statement.