Core definitions and primitives.
Print the document to a string using the given ribbon fraction
and page width.
The document (text s)
contains the literal string s
. The
string shouldn't contain any newline ('\n'
) characters. If the
string contains newline characters, the function 'literal' should be
used.
Helper function to construct spaces.
(showPrettyDoc doc)
takes the output PrettyDoc
from a
rendering function and transforms it to a String for printing.
Use the Wadler-Leijen algorithm to pretty print the doc
.
The algorithm uses a page width of width
and a ribbon
width of (ribbonfrac * width)
characters. The ribbon width is
the maximal amount of non-indentation characters on a line. The
parameter ribbonfrac
should be between 0.0
and 1.0
. If it is
lower or higher, the ribbon width will be 0 or width
respectively.
The document (nest lvl x)
renders document x
with the current
indentation level increased by lvl.
The line
document advances to the next line and indents to the
current nesting level. Document line
behaves like (text " ")
if the line break is undone by 'group'.
The group
combinator is used to specify alternative
layouts. The document (group x)
undoes all line breaks in
document x
. The resulting line is added to the current line if
that fits the page. Otherwise, the document x
is rendered without
any changes.
The empty document is, indeed, empty.
The document (char c)
contains the literal character c
. If the
character is a newline ('\n'
) the function returns a line
document. Ideally, the function 'line' should be used for line
breaks.
The breakLine
document advances to the next line and indents to
the current nesting level. Document breakLine
behaves like
'empty' if the line break is undone by 'group'.
Horizontal concatenation of documents
The abstract data type Doc
represents pretty documents.