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.
This package is on OPAM:
opam install prettiest
A version of the sexpr example is included in the test folder.
That folder also includes a larger example of pretty printing types.
>= "v0.10" & < "v0.11"