package prettiest
Non-greedy pretty printer
Install
Dune Dependency
Authors
Maintainers
Sources
0.0.1.tar.gz
sha256=8f2feda98b773d689db6e0b6fc12b1235816f46a0736db853c001d1a50a85109
md5=4b6930c4dd9444cede6b45a2f2560d32
Description
Implementation of Jean-Philippe Bernardy's A Pretty But Not Greedy Printer (Functional Pearl). PACMPL 1(ICFP): 6:1-6:21 (2017) (https://jyp.github.io/pdf/Prettiest.pdf).
Published: 19 Jan 2018
README
prettiest
Implementation of Jean-Philippe Bernardy's A Pretty But Not Greedy Printer (Functional Pearl). PACMPL 1(ICFP): 6:1-6:21 (2017) in OCaml. The author of the paper has a version in Haskell.
I make no promises about performance.
Example from the paper
A version of this example is included in the test folder. That folder also includes a larger example of pretty printing types.
type sexpr =
| Atom of string
| Sexpr of sexpr list
let rec pretty_sexpr xs =
let open Prettiest in
let open Prettiest.Infix in
match xs with
| Atom s -> text s
| Sexpr xs -> text "(" <> (sep (List.map ~f:pretty_sexpr xs)) <> text ")"
let test_data =
let abcd = Sexpr [Atom "a"; Atom "b"; Atom "c"; Atom "d"] in
let abcd4 = Sexpr [abcd; abcd; abcd; abcd] in
Sexpr [
Sexpr [Atom "abcde"; abcd4];
Sexpr [Atom "abcdefgh"; abcd4];
]
let fit = Option.value ~default:"did not fit"
let%expect_test "sexp" =
test_data |> pretty_sexpr |> Prettiest.render 80 |> fit |> print_endline;
Out_channel.newline stdout;
test_data |> pretty_sexpr |> Prettiest.render 20 |> fit |> print_endline;
[%expect {|
((abcde ((a b c d) (a b c d) (a b c d) (a b c d)))
(abcdefgh ((a b c d) (a b c d) (a b c d) (a b c d))))
((abcde ((a b c d)
(a b c d)
(a b c d)
(a b c d)))
(abcdefgh
((a b c d)
(a b c d)
(a b c d)
(a b c d))))
|}]
Dependencies (5)
-
jbuilder
>= "1.0+beta12"
-
ocaml-migrate-parsetree
< "2.0.0"
-
ppx_compare
>= "v0.10"
-
base
>= "v0.10" & < "v0.11"
-
ocaml
>= "4.04.1"
Dev Dependencies
None
Used by
None
Conflicts
None
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page