Module PPrintCombinators
Single characters
val lparen : PPrintEngine.documentval rparen : PPrintEngine.documentval langle : PPrintEngine.documentval rangle : PPrintEngine.documentval lbrace : PPrintEngine.documentval rbrace : PPrintEngine.documentval lbracket : PPrintEngine.documentval rbracket : PPrintEngine.documentval squote : PPrintEngine.documentval dquote : PPrintEngine.documentval bquote : PPrintEngine.documentval semi : PPrintEngine.documentval colon : PPrintEngine.documentval comma : PPrintEngine.documentval space : PPrintEngine.documentval dot : PPrintEngine.documentval sharp : PPrintEngine.documentval slash : PPrintEngine.documentval backslash : PPrintEngine.documentval equals : PPrintEngine.documentval qmark : PPrintEngine.documentval tilde : PPrintEngine.documentval at : PPrintEngine.documentval percent : PPrintEngine.documentval dollar : PPrintEngine.documentval caret : PPrintEngine.documentval ampersand : PPrintEngine.documentval star : PPrintEngine.documentval plus : PPrintEngine.documentval minus : PPrintEngine.documentval underscore : PPrintEngine.documentval bang : PPrintEngine.documentval bar : PPrintEngine.document
Delimiters
val precede : PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentprecede l xisl ^^ x.
val terminate : PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentterminate r xisx ^^ r.
val enclose : PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentenclose l r xisl ^^ x ^^ r.
val squotes : PPrintEngine.document -> PPrintEngine.documentval dquotes : PPrintEngine.document -> PPrintEngine.documentval bquotes : PPrintEngine.document -> PPrintEngine.documentval braces : PPrintEngine.document -> PPrintEngine.documentval parens : PPrintEngine.document -> PPrintEngine.documentval angles : PPrintEngine.document -> PPrintEngine.documentval brackets : PPrintEngine.document -> PPrintEngine.document
Repetition
val twice : PPrintEngine.document -> PPrintEngine.documenttwice docis the document obtained by concatenating two copies of the documentdoc.
val repeat : int -> PPrintEngine.document -> PPrintEngine.documentrepeat n docis the document obtained by concatenatingncopies of the documentdoc.
Lists and options
val concat : PPrintEngine.document list -> PPrintEngine.documentconcat docsis the concatenation of the documents in the listdocs.
val separate : PPrintEngine.document -> PPrintEngine.document list -> PPrintEngine.documentseparate sep docsis the concatenation of the documents in the listdocs. The separatorsepis inserted between every two adjacent documents.
val concat_map : ('a -> PPrintEngine.document) -> 'a list -> PPrintEngine.documentconcat_map f xsis equivalent toconcat (List.map f xs).
val separate_map : PPrintEngine.document -> ('a -> PPrintEngine.document) -> 'a list -> PPrintEngine.documentseparate_map sep f xsis equivalent toseparate sep (List.map f xs).
val separate2 : PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document list -> PPrintEngine.documentseparate2 sep last_sep docsis the concatenation of the documents in the listdocs. The separatorsepis inserted between every two adjacent documents, except between the last two documents, where the separatorlast_sepis used instead.
val optional : ('a -> PPrintEngine.document) -> 'a option -> PPrintEngine.documentoptional f Noneis the empty document.optional f (Some x)is the documentf x.
Text
val lines : string -> PPrintEngine.document listlines sis the list of documents obtained by splittingsat newline characters, and turning each line into a document viasubstring. This code is not UTF-8 aware.
val arbitrary_string : string -> PPrintEngine.documentarbitrary_string sis equivalent toseparate (break 1) (lines s). It is analogous tostring s, but is valid even if the stringscontains newline characters.
val words : string -> PPrintEngine.document listwords sis the list of documents obtained by splittingsat whitespace characters, and turning each word into a document viasubstring. All whitespace is discarded. This code is not UTF-8 aware.
val split : (char -> bool) -> string -> PPrintEngine.document listsplit ok ssplits the stringsbefore and after every occurrence of a character that satisfies the predicateok. The substrings thus obtained are turned into documents, and a list of documents is returned. No information is lost: the concatenation of the documents yields the original string. This code is not UTF-8 aware.
val flow : PPrintEngine.document -> PPrintEngine.document list -> PPrintEngine.documentflow sep docsseparates the documents in the listdocswith the separatorsepand arranges for a new line to begin whenever a document does not fit on the current line. This is useful for typesetting free-flowing, ragged-right text. A typical choice ofsepisbreak b, wherebis the number of spaces that must be inserted between two consecutive words (when displayed on the same line).
val flow_map : PPrintEngine.document -> ('a -> PPrintEngine.document) -> 'a list -> PPrintEngine.documentflow_map sep f docsis equivalent toflow sep (List.map f docs).
val url : string -> PPrintEngine.documenturl sis a possible way of displaying the URLs. A potential line break is inserted immediately before and immediately after every slash and dot character.
Alignment and indentation
val hang : int -> PPrintEngine.document -> PPrintEngine.documentval prefix : int -> int -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentprefix n b left righthas the following flat layout:left rightand the following non-flat layout:
left rightThe parameter
ncontrols the nesting ofright(when not flat). The parameterbcontrols the number of spaces betweenleftandright(when flat).
val jump : int -> int -> PPrintEngine.document -> PPrintEngine.documentjump n b rightis equivalent toprefix n b empty right.
val infix : int -> int -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentinfix n b middle left righthas the following flat layout:left middle rightand the following non-flat layout:
left middle rightThe parameter
ncontrols the nesting ofright(when not flat). The parameterbcontrols the number of spaces betweenleftandmiddle(always) and betweenmiddleandright(when flat).
val surround : int -> int -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentsurround n b opening contents closinghas the following flat layout:opening contents closingand the following non-flat layout:
opening contents closingThe parameter
ncontrols the nesting ofcontents(when not flat). The parameterbcontrols the number of spaces betweenopeningandcontentsand betweencontentsandclosing(when flat).
val soft_surround : int -> int -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentsoft_surroundis analogous tosurround, but involves more than one group, so it offers possibilities other than the completely flat layout (whereopening,contents, andclosingappear on a single line) and the completely developed layout (whereopening,contents, andclosingappear on separate lines). It tries to place the beginning ofcontentson the same line asopening, and to placeclosingon the same line as the end ofcontents, if possible.
val surround_separate : int -> int -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document list -> PPrintEngine.documentsurround_separate n b void opening sep closing docsis equivalent tosurround n b opening (separate sep docs) closing, except when the listdocsis empty, in which case it reduces tovoid.
val surround_separate_map : int -> int -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.document -> ('a -> PPrintEngine.document) -> 'a list -> PPrintEngine.documentsurround_separate_map n b void opening sep closing f xsis equivalent tosurround_separate n b void opening sep closing (List.map f xs).
Short-hands
val (!^) : string -> PPrintEngine.document!^sis a short-hand forstring s.
val (^/^) : PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentx ^/^ yseparatesxandywith a breakable space. It is a short-hand forx ^^ break 1 ^^ y.
val (^//^) : PPrintEngine.document -> PPrintEngine.document -> PPrintEngine.documentx ^//^ yis a short-hand forprefix 2 1 x y.