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
Examples:
(Fmt build-table '((def (fmt . head-1)))) => (("def" ('fmt . 'head-1)))(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
Examples:
(Fmt lookup 'def (Fmt build-table '((def (fmt . head-1))))) => (('fmt . 'head-1))
(null? (Fmt lookup 'when (Fmt build-table '((def (fmt . head-1)))))) => #t(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
Examples:
(Fmt get-prop 'fmt '((fmt . body))) => 'body(Fmt comment? tok)Test whether a token is a comment token.
Parameters:
ANY — Token to testReturns: BOOL — True if tok is a (%comment …) token
Examples:
(Fmt comment? (list '%comment "; note")) => #t
(Fmt comment? '(def x 1)) => #f(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: INTEGER — Estimated width in code points
Examples:
(Fmt width '(def x 1)) => 11(Fmt expr form col)Format any expression, writing the result to output.
Parameters:
ANY — Expression to formatINTEGER — Current indentation columnReturns: ANY — nil (output via display)
Examples:
(Fmt expr '(def x 'y) 0) => (def x 'y)(Fmt list form col table)Format a list form with indentation-aware pretty printing, writing the result.
Parameters:
LIST — List form to formatINTEGER — Current indentation columnALIST — Formatter tableReturns: ANY — nil (output via display)
Examples:
(Fmt list '(def x 1) 0 ()) => (def x 1)(Fmt body forms col)Format a sequence of body forms, one per line, writing the result.
Parameters:
LIST — Body formsINTEGER — Current indentation columnReturns: ANY — nil (output via display)
Examples:
(Fmt body '((a 1)) 0) => (a 1)(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)
Examples:
(Fmt tokens '((def x 1)) ()) => (def x 1)(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 lit/quasi/unquote forms to reader sugar?Returns: ANY — nil