Skip to content

Commit

Permalink
fix: type of Pp.paragraphf and add changelog
Browse files Browse the repository at this point in the history
We define the format string internally so that it can be enforced
somewhat.

Signed-off-by: Ali Caglayan <[email protected]>
  • Loading branch information
Alizter committed Nov 16, 2023
1 parent 6749c14 commit 7f5a115
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Unreleased

- Add `Pp.verbatimf`. (#18, @mbarbin)

- Add `Pp.paragraph` and `Pp.paragraphf` (#19, @Alizter)

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

1.2.0
Expand Down
6 changes: 4 additions & 2 deletions src/pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ include Ast
let of_ast = Fun.id
let to_ast = Fun.id

type ('a, 'tag) format_string = ('a, unit, string, 'tag t) format4

let rec map_tags t ~f =
match t with
| Nop -> Nop
Expand Down Expand Up @@ -145,10 +147,10 @@ let space = break ~nspaces:1 ~shift:0
let cut = break ~nspaces:0 ~shift:0
let newline = Newline
let text s = Text s
let textf fmt = Printf.ksprintf text fmt
let textf (fmt : ('a, 'tag) format_string) = Printf.ksprintf text fmt
let tag tag t = Tag (tag, t)
let paragraph s = hovbox (text s)
let paragraphf fmt = hovbox (textf fmt)
let paragraphf (fmt : ('a, 'tag) format_string) = Printf.ksprintf paragraph fmt

let enumerate l ~f =
vbox
Expand Down
2 changes: 1 addition & 1 deletion src/pp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ val paragraph : string -> 'tag t

(** [paragraphf s] is [textf s] followed by a [hovbox]. The [textf] version of
[paragraph]. *)
val paragraphf : ('tag t, unit, string, 'b t) format4 -> 'tag t
val paragraphf : ('a, unit, string, 'tag t) format4 -> 'a

(** [enumerate l ~f] produces an enumeration of the form:
Expand Down
3 changes: 3 additions & 0 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,6 @@ let%expect_test "paragraph" =
-< box + text >-----------
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum euismod,
nisl eget aliquam ultricies. |}]

let%expect_test "paragraphf" = print (Pp.paragraphf "Hello World%s" "!");
[%expect {| Hello World! |}]

0 comments on commit 7f5a115

Please sign in to comment.