Comment-preserving s-expression formatter on the Fmt class.
Formatting logic is %-private (the mutually-recursive printers call each other directly); the Fmt class is the API.
FmtComment-preserving, data-driven pretty printer for x-lang s-expressions.
Build a formatter table from construct declarations with (Fmt build-table …), then (Fmt tokens toks table) prints them. A form under 60 chars wide prints as-is; wider ones indent per the table’s
fmtproperty (head-1 / head-kw / body / default).
(Fmt build-table constructs)Build a formatter lookup table from construct declarations.
Parameters:
LIST — Construct declarations (from XEON)Returns: ALIST — Lookup table mapping names to property lists
(Fmt lookup name table)Look up formatting properties for a construct name.
Parameters:
SYMBOL — Form name to look upALIST — Table from (Fmt build-table)Returns: LIST — Property list, or nil
(Fmt get-prop key props)Get a specific property from a construct property list.
Parameters:
SYMBOL — Property keyLIST — Property list from (Fmt lookup)Returns: ANY — Property value, or nil
(Fmt comment? tok)Test whether a token is a comment token.
Parameters:
ANY — Token to testReturns: BOOL — True if tok is a (%comment …) token
(Fmt width form)Estimate the display width of a form in CODE POINTS (via write-to-str; a comment counts as 80). Code points approximate display columns except for double-width/combining glyphs (wcwidth is a known gap).
Parameters:
ANY — Form to measureReturns: INT — Estimated width in code points
(Fmt expr form col)Format any expression, writing the result to output.
Parameters:
ANY — Expression to formatINT — Current indentation columnReturns: ANY — nil (output via display)
(Fmt list form col table)Format a list form with indentation-aware pretty printing, writing the result.
Parameters:
LIST — List form to formatINT — Current indentation columnALIST — Formatter tableReturns: ANY — nil (output via display)
(Fmt body forms col)Format a sequence of body forms, one per line, writing the result.
Parameters:
LIST — Body formsINT — Current indentation columnReturns: ANY — nil (output via display)
(Fmt tokens tokens table)Format a list of top-level tokens with the given construct table, writing the result.
Parameters:
LIST — Token list from the tokenizerALIST — Formatter table from (Fmt build-table)Returns: ANY — nil (output via display)
(Fmt fold-sugar! on)Set whether (lit x) / (quasi x) / (unquote x) fold to ‘ ` , sugar in output. ON is the docs/syntax.md ruling for post-boot code; a driver formatting a BOOT-CONSTRAINED file (its text loads before the quote reader arms) must turn it OFF or the output cannot boot (#307).
Parameters:
BOOL — Fold quote-family forms to reader sugar?Returns: ANY — nil