5.4 Writing Shrubbery Notation
(require shrubbery/write) | package: shrubbery-lib |
procedure
(write-shrubbery v [ port #:pretty? pretty? #:width width #:armor? armor? #:prefer-multiline? prefer-multiline?]) → void? v : any/c port : output-port? = (current-output-port) pretty? : any/c = #f width : (or/c exact-nonnegative-integer?) = #f armor? : any/c = #f prefer-multiline? : any/c = #f
The default mode with pretty? as #false prints in a simple and relatively fast way (compared to pretty-shrubbery). When pretty? is a true value, single-line output is preferred if width is #false, otherwise it is preferred only when the line fits with width columns. Use pretty-shrubbery to gain more control over line choices when printing.
If pretty? is #false or armor? is a true value, then the printed form is line- and column-insensitive. If pretty? is a true value, armor? is #f, and prefer-multiline? is a true value, then line breaks are used instead of « and ».
Note that write-shrubbery expects an S-expression, not a syntax object, so it cannot use raw text properties. See also shrubbery-syntax->string.
procedure
(pretty-shrubbery v [ #:armor? armor? #:prefer-multiline? prefer-multiline?]) → any/c v : any/c armor? : any/c = #f prefer-multiline? : any/c = #f
The description is an S-expression DAG (directed acyclic graph) that represents pretty-printing instructions and alternatives:
string or bytes: print literally.
'nl: print a newline followed by spaces corresponding to the current indentation.
`(seq ,doc ...): print each doc in sequence, each with the same indentation.
`(nest ,n ,doc): print doc with the current indentation increased by n.
`(align ,doc): print doc with the current indentation set to the current output column.
`(or ,doc ,doc): print either doc; always taking the first doc in an 'or will produce single-line output if prefer-multiline? is #f, while always taking the second doc will print a maximal number of lines.
The description can be a DAG because 'or alternatives might have components in common. In the worst case, a tree view of the instructions can be exponentially larger than the DAG representation.