Skip to content

Commit

Permalink
Update to latest ocamlformat
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Mar 29, 2021
1 parent 1a34a8a commit 05660f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.14.2
version=0.17.0
break-separators=before
dock-collection-brackets=false
break-sequences=true
Expand Down
6 changes: 3 additions & 3 deletions src/pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let rec filter_map_tags t ~f =
let t = filter_map_tags t ~f in
match f tag with
| None -> t
| Some tag -> Tag (tag, t) )
| Some tag -> Tag (tag, t))
| Format f -> Format f

module Render = struct
Expand Down Expand Up @@ -224,10 +224,10 @@ let chain l ~f =
box ~indent:3
(seq
(verbatim
( if i = 0 then
(if i = 0 then
" "
else
"-> " ))
"-> "))
(f x)))))

module O = struct
Expand Down
12 changes: 7 additions & 5 deletions src/pp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,15 @@ val to_fmt_with_tags :

(** Inject a classic formatter in a document.
Disclaimer: this function is to meant to help using [Pp] in
existing code that already use the [Format] module without having
to port everything to [Pp]. It is not meant as the normal way to
create [Pp.t] values.
*)
Disclaimer: this function is to meant to help using [Pp] in existing code
that already use the [Format] module without having to port everything to
[Pp]. It is not meant as the normal way to create [Pp.t] values. *)
val of_fmt : (Format.formatter -> 'a -> unit) -> 'a -> _ t

(** {1 Ast} *)

module Ast : sig
(** Stable representation useful for serialization *)
type 'a t =
| Nop
| Seq of 'a t * 'a t
Expand All @@ -204,6 +203,9 @@ module Ast : sig
| Tag of 'a * 'a t
end

(** [of_ast t] [Ast.t] to [Pp.t] *)
val of_ast : 'a Ast.t -> 'a t

(** [to_ast t] will try to convert [t] to [Ast.t]. When [t] contains values
constructed with [of_fmt], this function will fail and return [Error ()] *)
val to_ast : 'a t -> ('a Ast.t, unit) result
20 changes: 10 additions & 10 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ let%expect_test _ =
let%expect_test _ =
print
(Pp.vbox
( Pp.box (Pp.text "Error: something went wrong!")
(Pp.box (Pp.text "Error: something went wrong!")
++ Pp.cut
++ Pp.box (Pp.text "Here are a few things you can do:")
++ Pp.cut
Expand All @@ -180,7 +180,7 @@ let%expect_test _ =
; "take a break from your keyboard"
; "clear your head and try again"
]
] ));
]));
[%expect
{|
Error: something went wrong!
Expand All @@ -200,24 +200,24 @@ let%expect_test _ =
let%expect_test _ =
print
(Pp.hovbox ~indent:2
( Array.make 50 (Pp.char 'x')
(Array.make 50 (Pp.char 'x')
|> Array.to_list
|> Pp.concat
~sep:(Pp.custom_break ~fits:("", 2, "") ~breaks:(" \\", -1, "")) ));
~sep:(Pp.custom_break ~fits:("", 2, "") ~breaks:(" \\", -1, ""))));
[%expect
{|
x x x x x x x x x x x x x x x x x x x x x x x x x \
x x x x x x x x x x x x x x x x x x x x x x x x x
|}]

let pp_pair ppf (a,b) = Format.fprintf ppf "(%i,@ %i)" a b
let pp_pair ppf (a, b) = Format.fprintf ppf "(%i,@ %i)" a b

let%expect_test _ =
print (
Pp.text "hello" ++ Pp.newline ++
Pp.vbox (Pp.of_fmt pp_pair (1,2)) ++ Pp.space ++ Pp.text "foo"
);
[%expect{|
print
(Pp.text "hello" ++ Pp.newline
++ Pp.vbox (Pp.of_fmt pp_pair (1, 2))
++ Pp.space ++ Pp.text "foo");
[%expect {|
hello
(1,
2)
Expand Down

0 comments on commit 05660f4

Please sign in to comment.