"Pretty PRINTer for ZILF" "This package is based on the Guile pretty printer (ice-9 pretty-print), released under the GPLv3: https://github.com/skangas/guile/blob/master/module/ice-9/pretty-print.scm" "The main entry point is PPRINT, which takes a single argument. If given an atom, it will try to look up a definition by that name, and print it as a call to DEFINE, DEFMAC, ROUTINE, OBJECT, SETG, etc. Otherwise it will simply print the object." "An alternate entry point is PRETTY-PRINT, which prints the argument exactly as given even if it's an atom, and also takes some optional parameters to control the formatting." "By default, a few types such as LIST and FUNCTION will have their PRINTTYPEs set to PPRINT when this package is loaded. To change that, call PPRINT-TYPES after loading the package: ;only use PPRINT for these types > ;don't use PPRINT for any types" #SPLICE ()> >> <1? >>> %> % > '(QUOTE GVAL LVAL)> >>> %> % <2 .F>> %> % > "!") (ELSE "")> "'") (<==? .HEAD GVAL> ",") (<==? .HEAD LVAL> ".")>>> <+ .COL >>> >> >>> > > ) (PT )) ;"XXX use .PRINC?" > > .RES> "] VECTOR ["[" "]"] SEGMENT ["!<" ">"] ;"TABLE is its own PRIMTYPE" TABLE ["#TABLE (" ")"])> ,STD-BRACKETS>> <2 .R>) ( ,STD-BRACKETS>> [> " " <1 <2 .R>>> <2 <2 .R>>]) (ELSE >)>> > >>> % % % % % .COL>>) (<=? .OBJ <>> " .COL>) ( % ;"A proper list: do our own list printing so as to catch read macros that appear in the middle of the list." >) (ELSE % .COL>)>> >) (ELSE .COL>)>) (ELSE .COL)>> % % % % >) (ELSE .COL>)>>> ;"Prints some shit. OBJ: The object to print. COL: The column where we are now. EXTRA: The number of extra columns to reserve at the right margin. PP-STRUC: The PP function to use for printing the object if it needs to be split across multiple lines. Returns: The column where we are after printing." %> % % % % % ;"may have to split on multiple lines" 1> .MAX-EXPR-WIDTH>> .MAX-EXPR-WIDTH "" > >> >> ;"all can be printed on one line" .COL>) (ELSE )>) (ELSE )>> .COL> .EXTRA ,PP-EXPR>) (<=? .EXPR <>> " .COL>) ( > > ) (> ,MAX-CALL-HEAD-WIDTH> <> <> ,PP-EXPR>) (ELSE )>) (ELSE )>) (ELSE )>> ;"(head item1 item2 item3)" )) .COL>>> .COL* <+ .COL* 1> .EXTRA .PP-ITEM <2 .BK>>>> ;"(item1 item2 item3)" > .COL>> >> ;"Prints the items of L downward, one per line, then ends with KET. L: The list of items to print. COL1: The column where we are now. COL2: The column where the items should be lined up. EXTRA: The number of extra columns to reserve at the right margin. PP-ITEM: The PP function to use for printing each item. KET: The closing bracket to print on the last line. Returns: The column where we are after printing." % % % % % ) (ELSE % ) (EXTRA <+ .EXTRA >) (ELSE 0)>)) .EXTRA .PP-ITEM>> >)>>>> ;"Helper for PP-GENERAL. REST: The items left to print. COL1: The column where the final items (handled by the last PP function) should be lined up. COL2: The column where we are now. COL3: The column where the initial items (handled by PP functions before the last) should be lined up. Returns: The column where we are after printing." >> ) (REST ) (EXTRA* <+ .EXTRA 1>) (ELSE 0)>)) .EXTRA* .PP-1> .COL3>>) (ELSE )>> >> ) (REST ) (EXTRA* <+ .EXTRA 1>) (ELSE 0)>)) .EXTRA* .PP-2>>>) (ELSE )>> > ;"Prints a structured expression using the supplied PP functions for various parts. EXPR: The object to print. COL: The column where we are now. EXTRA: The number of extra columns to reserve at the right margin. NAMED?: If true, the 2nd element of the structure will be printed on the same line as the 1st, and the PP functions shift down by 1 (e.g. PP-1 is used for the 3rd). PP-1: The PP function to use for the 2nd element. If omitted, the remaining PP functions shift up by 1. PP-2: The PP function to use for the 3rd element. If omitted, the remaining PP functions shift up by 1. PP-3: The PP function to use for the 4th and following elements. Returns: The column where we are after printing." ) (REST ) (BK ) (BRA <1 .BK>) (KET <2 .BK>) (COL* >)) ) (ELSE )> >> >> > >) (ELSE )>> .COL* <+ .COL* 1>>>> > > ATOM>>> ,PP-EXPR>> > > > ATOM> >> ,PP-EXPR>> ,PP-EXPR-LIST <> ,PP-EXPR>> <> ,PP-AND>> ;"Define formatting style (change these to suit your style)" ,PP-FUNCTION) ( ,PP-COND) ( ,PP-AND) ( ,PP-DEFINE) ( ,PP-DO) ( ,PP-OBJECT) (ELSE <>)>> ;"TODO? * FORM style mirroring the style of the form being constructed:
> * MAKE-* style: 'BAZ 123> * IF-* style: > * TELL style fitting multiple exprs on one line and keeping atoms together with the next expr: CR CR D CR> * DEFAULT-DEFINITION style: > * SYNTAX style: * SCOPE-STAGE style: ) ()> * [ADD-]TELL-TOKENS style: BAR * * BLAH-BLAH-BLAH > * styles for individual object properties (e.g. THINGS) " > >) (ELSE )> T> >> .L> > ;"Pretty-prints an object, with optional formatting controls." ) (PER-LINE-PREFIX "")) > .MAX-EXPR-WIDTH .PER-LINE-PREFIX T>>> > .OBJ) ( ) ( ) (ELSE )>> >) ( > LIST>>) ( >) ( >) ( >) (ELSE >)>) (ELSE .OBJ)>> ;"Pretty-prints a definition or object." >> ;"Gets or sets the list of types whose PRINTTYPEs are ,PPRINT. Get: Set: ;clears other types Clear: > Will not alter the PRINTTYPE of a type whose PRINTTYPE is already set to something other than ,PPRINT." !>) ,PPRINT> .T) (ELSE )>> >> > > .L> )) >> .TYPES>> >)> .L>