otf.pretty: A pretty printing library#

The library is based on Christian Lindig’s “strictly pretty” [pdf] article.

The code was modified to add the features from the QuickC– implementation

class otf.pretty.Doc#

Type used to represent documents

This constructor should never be called directly

Documents can be concatenated via the + operator.

to_string(width=80)#

Render this document to a string

Parameters

width (int) –

otf.pretty.EMPTY = DocNil()#

The empty document

otf.pretty.text(s)#

Turns a string into a document

Parameters

s (str) –

Return type

Doc

otf.pretty.BREAK = DocBREAK(text=' ')#

A break is either rendered as a space or a newline followed by a spaces (the number of spaces is determined by the indentation level)

otf.pretty.nest(indentation, doc)#

Set the indentation level for a document.

Parameters
  • indentation (int) –

  • doc (Doc) –

Return type

Doc

otf.pretty.fgrp(doc)#

BREAKs inside the group are considered individually.

Parameters

doc (Doc) –

Returns

Doc:

otf.pretty.hgrp(doc)#

BREAKs inside the group are never always into newline.

Parameters

doc (Doc) –

Returns

Doc:

otf.pretty.vgrp(doc)#

BREAKs inside the group are never turned into newline.

Parameters

doc (Doc) –

Returns

Doc: