diff --git a/README.md b/README.md index c3feb6b..eb5ff25 100644 --- a/README.md +++ b/README.md @@ -368,12 +368,14 @@ Lists: * `separate : t -> t list -> t` Concatenate the list of documents with no space but adding a separator in between. `separate sep [d1; ...; dn]` is like `d1 ^-^ sep ^-^ d2 ^-^ sep ... sep ^-^ dn`. OCaml values: +* `OCaml.unit : unit -> t` Pretty-print the unit value. * `OCaml.bool : bool -> t` Pretty-print a `bool`. * `OCaml.int : int -> t` Pretty-print an `int`. * `OCaml.float : float -> t` Pretty-print a `float`. * `OCaml.string : string -> t` Pretty-print a `string`. * `OCaml.option : ('a -> t) -> 'a option -> t` Pretty-print an `option`. * `OCaml.list : ('a -> t) -> 'a list -> t` Pretty-print a `list`. +* `OCaml.tuple : t list -> t` Pretty-print a tuple of values. A pretty-printer for the pretty-printer itself: * `Debug.pp_document : t -> t` Pretty-print a document's structure. diff --git a/smartPrint.ml b/smartPrint.ml index ba3705e..0486f08 100644 --- a/smartPrint.ml +++ b/smartPrint.ml @@ -355,6 +355,9 @@ let lines (s : string) : t = (split s (fun c -> c = '\n') 0 0) module OCaml = struct + let unit (_ : unit) : t = + !^ "()" + let bool (b : bool) : t = !^ (string_of_bool b) @@ -374,6 +377,9 @@ module OCaml = struct let list (d : 'a -> t) (l : 'a list) : t = brakets @@ nest_all (space ^^ separate (!^ ";" ^^ space) (List.map d l) ^^ space) + + let tuple (ds : t list) : t = + parens @@ nest @@ separate (!^ "," ^^ space) ds end module Debug = struct diff --git a/smartPrint.mli b/smartPrint.mli index ee60e40..5b3678e 100644 --- a/smartPrint.mli +++ b/smartPrint.mli @@ -94,6 +94,9 @@ val separate : t -> t list -> t (** {1 OCaml values} *) (** Pretty-printing of OCaml values. *) module OCaml : sig + (** Pretty-print the unit value. *) + val unit : unit -> t + (** Pretty-print a [bool]. *) val bool : bool -> t @@ -111,6 +114,9 @@ module OCaml : sig (** Pretty-print a [list]. *) val list : ('a -> t) -> 'a list -> t + + (** Pretty-print a tuple of values. *) + val tuple : t list -> t end (** {1 Debugging} *) diff --git a/test.ml b/test.ml index f2e2a66..085cbd8 100644 --- a/test.ml +++ b/test.ml @@ -55,6 +55,7 @@ let main () = print_document @@ nest @@ lines "adipisicing elit,\n\nsed do eiusmod tempo incididunt ut labore et dolore"; print_document @@ indent @@ nest @@ lines "adipisicing elit,\n\nsed do eiusmod tempo incididunt ut labore et dolore"; print_document @@ indent @@ pp false @@ Let ("x", Var "x", Let ("x", Var "x", Var "y")); - print_document @@ pp false @@ App (Var "f", Let ("x", Var "x", Var "y")) + print_document @@ pp false @@ App (Var "f", Let ("x", Var "x", Var "y")); + print_document @@ OCaml.unit () ^^ OCaml.tuple [!^ "x"; OCaml.int 0] ;;main () diff --git a/test.out b/test.out index 97a733e..8cf6fdf 100644 --- a/test.out +++ b/test.out @@ -313,3 +313,7 @@ f let x = x in y ************************* +GroupOne (false, "()", Space, "(", GroupOne (true, "x", ",", Space, Space, "0"), ")") +************************* +() (x, 0) +*************************