Fmlib_pretty.PrettyPretty Printer: Generate nicely formatted ascii text.
module Stream : Fmlib_std.Interfaces.SOURCE with type item := charLazy stream of characters
val empty : tAn empty document.
val text : string -> ttext str A document with the unbreakable string str. It is highly recommended that the string does not contain newlines. Newlines in a text string confuse the layouter.
val substring : string -> int -> int -> tsubstring str start length A document with the unbreakable string str starting at position start and having length.
This is a useful function if you want to create documents from a larger string without splittig the string. substring is a reference into a possible larger string.
val fill : int -> char -> tfill n c A document with n repetitions of the character c.
val char : char -> tchar c A document with the character c.
val break : string -> tbreak str A break hint with the alternative text str.
val cut : tcut A break hint with an empty alternative text.
val space : tspace A break hint with one blank as alternative text.
doc1 <+> doc2 Concatentate the document x with the lazy document y.
Lazy documents are useful for large documents.
doc1 <+> doc2 Concatentate the lazy document x with the lazy document y.
Lazy documents are useful for large documents.
separated_by sep list Concatenate all documents in the list of documents separated by sep.
paragraphs ps
Print the paragraphs in ps separated by newlines. The function works best if each paragraph ends in a newline. paragraphs ps is equivalent to separated_by cut ps.
nest n x
The document x indented by n blanks.
This is the basic function to indicate a substructure to the pretty printer. The substructure is indented with respect to the parent document.
The indentation is valid after each effective line break. It is usually convenient to group the whole substructure and put a break hint before the group and group the parent structure and the substructure. This makes sure that either the parent and the child fit on a line or the child begins on a newline and is indented. See the function parent_child below which does exactly that.
The same as nest where the indented document is a lazy document.
group x
Treat all break hints belonging directly to x consistently. Either print all as newlines or print all with their alternative text.
This is the basic operation to decide break hints.
If the whole group and all text which follows until the next break hint after the group fits on a line, then all break hints (directly or indirectly) in the group are flattened i.e. printed with their alternative texts.
If the whole group does not fit, then all break hints belonging directly to the group are printed as effective newlines. The breaks of inner groups might be flattened depending on the length of the inner groups.
Grouping is idempotent, i.e. group (group x) is the same as group x.
parent_child hint indent parent child
Put the parent and the child in a group and separate them by a break hint with the alternative text hint. Furthermore put the child in a separate group.
Equivalent to
parent
<+> nest indent (break hint <+> group child)
|> grouppack str list Pack as many documents of the list of documents as possible into a line. I.e. separate all documents by a break hint with str in an own group as an alternative text.
stack str list Put a break hint between all documents in the list.
No grouping is done. I.e. if the list does not belong to any group or is in a group where all breaks are effective, then each document in the list is printed on a separated line.
The same as separated_by (break str) list.
stack_or_pack str list Separate all documents of the list by a break hint with alternative text str and either print all break hints as newlines of with the alternative text str.
This is effectively stack str list |> group.
It should not be confused with stack str list where each break hint can be flattened individually.
val wrap_words : string -> twrap_words str
Split the string str into words (words are substrings of str not containing whitespace, newline, CR and tab are treated as whitespace) and pack as many of them onto a line.
val wrap_words_list : string list -> tThe same as wrap_words str where str is the string of all concatenated strings in the list separated by a whitespace character.
layout width doc Layout the document doc with a the line width into a character stream.
layout width ribbon x Layout the document x with a the line width and the ribbon width. Note: width is the desired complete line width and ribbon is the desired width of a line without its indentation.
val write_to_channel : Stdlib.out_channel -> Stream.t -> unitWrite a character stream to an output channel.
val to_string : Stream.t -> stringConvert a character stream to a string.