IdrisDoc: Text.PrettyPrint.WL.Core

Text.PrettyPrint.WL.Core

Core definitions and primitives.

writeDoc : (fname : String) -> (rfrac : Double) -> (width : Int) -> (doc : Doc) -> IO (Either FileError ())
toString : (rfrac : Double) -> (width : Int) -> (doc : Doc) -> String

Print the document to a string using the given ribbon fraction
and page width.

text : (str : String) -> Doc

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.

spaces : (n : Int) -> String

Helper function to construct spaces.

showPrettyDoc : (doc : PrettyDoc) -> String

(showPrettyDoc doc) takes the output PrettyDoc from a
rendering function and transforms it to a String for printing.

render : (rfrac : Double) -> (width : Int) -> (doc : Doc) -> PrettyDoc

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.

nesting : (f : Int -> Doc) -> Doc
nest : (lvl : Int) -> (x : Doc) -> Doc

The document (nest lvl x) renders document x with the current
indentation level increased by lvl.

line : Doc

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'.

group : Doc -> Doc

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.

fold : (f : Doc -> Doc -> Doc) -> (ds : List Doc) -> Doc
empty : Doc

The empty document is, indeed, empty.

column : (f : Int -> Doc) -> Doc
char : (c : Char) -> Doc

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.

breakLine : Doc

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'.

beside : Doc -> Doc -> Doc

Horizontal concatenation of documents

data Doc : Type

The abstract data type Doc represents pretty documents.

Empty : Doc
Chara : (c : Char) -> Doc
Text : (len : Int) -> (str : String) -> Doc
Line : (undone : Bool) -> Doc
Cat : (x : Doc) -> (y : Doc) -> Doc
Nest : (lvl : Int) -> (x : Doc) -> Doc
Union : (x : Doc) -> (y : Doc) -> Doc
Column : (f : Int -> Doc) -> Doc
Nesting : (f : Int -> Doc) -> Doc