package ansifmt

  1. Overview
  2. Docs
type t

Represents a formatting element.

and pair =
  1. | Parentheses
  2. | Brackets
  3. | Braces
  4. | Custom_pair of string * string

Represents a pair of characters (e.g. parentheses).

val singleton : Token.t -> t

singleton token creates a singleton element of token.

val blob : Token.t list -> t

blob tokens groups tokens into an element.

val cluster : t list -> t

cluster elements groups elements together.

val indented : indent_count:int -> t -> t option

indented ~indent_count element produces a new element that will be indented indent_count times when formatting it. Returns None if indent_count is negative.

val indented_exn : indent_count:int -> t -> t

indented_exn ~indent_count element produces a new element that will be indented indent_count times when formatting it. Raises Invalid_arg if indent_count is negative.

val parenthesized : ?pair:pair -> ?condition:(t -> bool) -> t -> t

parenthesized ~pair ?condition element produces a new element that will be surrounded by a pair when formatting it. A condition can be optionally provided that will leave the element as-is if it is not met.

val intercalated : separating:Token.t list -> t -> t

intercalated ~separating elements produces a new element where the separating list of tokens is intercalated between the elements.

val sequence : pair:pair -> t -> t

sequence ~pair elements produces a new element where the elements are separated by a comma (and a space) and surrounded by pair.

val lines : t -> t

lines elements produces a new element that intersperses a line break between elements when formatting it, WITHOUT a trailing newline.

val format : ?stylizer:Formatting.Stylizer.t -> t -> string

format ~stylizer element renders the element into a string using the stylizer.

OCaml

Innovation. Community. Security.