Add some primitives to make writing formatters easier
* ocaml_list * quoted * const * record
This commit is contained in:
parent
126c91fcd5
commit
4314dd7db3
|
@ -138,6 +138,29 @@ module Fmt = struct
|
||||||
let nl = Format.pp_print_newline
|
let nl = Format.pp_print_newline
|
||||||
|
|
||||||
let prefix f g ppf x = f ppf; g ppf x
|
let prefix f g ppf x = f ppf; g ppf x
|
||||||
|
|
||||||
|
let ocaml_list pp fmt = function
|
||||||
|
| [] -> Format.pp_print_string fmt "[]"
|
||||||
|
| l ->
|
||||||
|
Format.fprintf fmt "@[<hv>[ %a@ ]@]"
|
||||||
|
(list ~pp_sep:(fun fmt () -> Format.fprintf fmt "@,; ")
|
||||||
|
pp) l
|
||||||
|
|
||||||
|
let quoted fmt = Format.fprintf fmt "%S"
|
||||||
|
|
||||||
|
let const
|
||||||
|
: 'a t -> 'a -> unit t
|
||||||
|
= fun pp a' fmt () -> pp fmt a'
|
||||||
|
|
||||||
|
let record fmt = function
|
||||||
|
| [] -> Format.pp_print_string fmt "{}"
|
||||||
|
| xs ->
|
||||||
|
let pp fmt (field, pp) =
|
||||||
|
Format.fprintf fmt "@[<hov 1>%s@ =@ %a@]"
|
||||||
|
field pp () in
|
||||||
|
let pp_sep fmt () = Format.fprintf fmt "@,; " in
|
||||||
|
Format.fprintf fmt "@[<hv>{ %a@ }@]"
|
||||||
|
(Format.pp_print_list ~pp_sep pp) xs
|
||||||
end
|
end
|
||||||
|
|
||||||
(* This is ugly *)
|
(* This is ugly *)
|
||||||
|
|
Loading…
Reference in New Issue