pyk.kast.pretty module

class PrettyPrinter(definition: KDefinition, extra_unparsing_modules: Iterable[KFlatModule] = (), patch_symbol_table: Callable[[SymbolTable], None] | None = None, unalias: bool = True, sort_collections: bool = False)[source]

Bases: object

definition: KDefinition
print(kast: KAst) str[source]

Print out KAST terms/outer syntax.

Parameters:

kast – KAST term to print.

Returns:

Best-effort string representation of KAST term.

property symbol_table: dict[str, Callable[[...], str]]
assoc_with_unit(assoc_join: str, unit: str) Callable[[...], str][source]
build_symbol_table(definition: KDefinition, extra_modules: Iterable[KFlatModule] = (), opinionated: bool = False) SymbolTable[source]

Build the unparsing symbol table given a JSON encoded definition.

Parameters:

definition – JSON encoded K definition.

Returns:

Python dictionary mapping klabels to automatically generated unparsers.

indent(text: str, size: int = 2) str[source]
paren(printer: Callable[[...], str]) Callable[[...], str][source]
unparser_for_production(prod: KProduction) Callable[[...], str][source]