File: pretty_printer.mli

package info (click to toggle)
janest-base 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,896 kB
  • sloc: ml: 37,596; ansic: 251; javascript: 114; makefile: 21
file content (48 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(** A list of pretty printers for various types, for use in toplevels.

    [Pretty_printer] has a [string list ref] with the names of [pp] functions matching the
    interface:

    {[
      val pp : Format.formatter -> t -> unit
    ]}

    The names are actually OCaml identifier names, e.g., "Base.Int.pp".  Code for
    building toplevels (this code is not in Base) evaluates the strings to yield the
    pretty printers and register them with the OCaml runtime. *)

open! Import

(** [all ()] returns all pretty printers that have been [register]ed. *)
val all : unit -> string list


(** Modules that provide a pretty printer will match [S]. *)
module type S = sig
  type t

  val pp : Formatter.t -> t -> unit
end

(** [Register] builds a [pp] function from a [to_string] function, and adds the
    [module_name ^ ".pp"] to the list of pretty printers.  The idea is to statically
    guarantee that one has the desired [pp] function at the same point where the [name] is
    added. *)
module Register (M : sig
    type t

    val module_name : string
    val to_string : t -> string
  end) : S with type t := M.t

(** [Register_pp] is like [Register], but allows a custom [pp] function rather than using
    [to_string]. *)
module Register_pp (M : sig
    include S

    val module_name : string
  end) : S with type t := M.t

(** [register name] adds [name] to the list of pretty printers.  Use the [Register]
    functor if possible. *)
val register : string -> unit