Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Pp.verbatimf #18

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased
----------

- Add `Pp.verbatimf`. (@mbarbin)

- Remove `of_fmt` constructor. (#17, @Alizter)

1.2.0
Expand Down
1 change: 1 addition & 0 deletions src/pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ let hbox t = Hbox t
let hvbox ?(indent = 0) t = Hvbox (indent, t)
let hovbox ?(indent = 0) t = Hovbox (indent, t)
let verbatim x = Verbatim x
let verbatimf fmt = Printf.ksprintf verbatim fmt
let char x = Char x
let custom_break ~fits ~breaks = Break (fits, breaks)

Expand Down
3 changes: 3 additions & 0 deletions src/pp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ val concat_mapi : ?sep:'tag t -> 'a list -> f:(int -> 'a -> 'tag t) -> 'tag t
(** An indivisible block of text. *)
val verbatim : string -> 'tag t

(** Same as [verbatim] but take a format string as argument. *)
val verbatimf : ('a, unit, string, 'tag t) format4 -> 'a

(** A single character. *)
val char : char -> 'tag t

Expand Down
4 changes: 4 additions & 0 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Hello 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%expect_test "verbatimf" =
print (Pp.verbatimf "ident%d" 42);
[%expect {| ident42 |}]

(* Difference between box and hovbox *)
let%expect_test _ =
let pp f = f (xs 50 ++ Pp.break ~nspaces:2 ~shift:(-1) ++ xs 10) in
Expand Down