Skip to content
anlun edited this page Feb 28, 2013 · 5 revisions

It is the library for pretty printing written in Kotlin. This library is the Kotlin representation of P. Wadler 'A prettier printer' that was originally written in Haskell.


The main concept of library is the document. It can be operated with several methods:

fun nil() : PrimeDoc

generates empty document.

fun text(text : String) : PrimeDoc

creates a document by string. This string has to contain no newline symbols.

fun line() : PrimeDoc

produces a document representation of linebreaker.

fun beside(leftDoc : PrimeDoc, rightDoc) : PrimeDoc

combines horizontally 2 documents. Documents will be concantenated on last line of leftDoc and first line of rightDoc.

fun group(doc : PrimeDoc)

creates a document with 2 alternative layouts. The first one is the document there all linebreakers changed to whitespaces. And the second one is original doc. The pretty method that produces a finish output will choose between these 2 layouts.

The documents horizontal combination also can be represented by (+) operator. As example,

leftDoc + rightDoc

There are some utility functions:

fun bracket(openBracket : String, doc : PrimeDoc, closeBracket : String) : PrimeDoc
Clone this wiki locally