English

A Pretty Expressive Printer (with Appendices)

Programming Languages 2023-10-04 v1

Abstract

Pretty printers make trade-offs between the expressiveness of their pretty printing language, the optimality objective that they minimize when choosing between different ways to lay out a document, and the performance of their algorithm. This paper presents a new pretty printer, Πe\Pi_e, that is strictly more expressive than all pretty printers in the literature and provably minimizes an optimality objective. Furthermore, the time complexity of Πe\Pi_e is better than many existing pretty printers. When choosing among different ways to lay out a document, Πe\Pi_e consults a user-supplied cost factory, which determines the optimality objective, giving Πe\Pi_e a unique degree of flexibility. We use the Lean theorem prover to verify the correctness (validity and optimality) of Πe\Pi_e, and implement Πe\Pi_e concretely as a pretty printer that we call PrettyExpressive. To evaluate our pretty printer against others, we develop a formal framework for reasoning about the expressiveness of pretty printing languages, and survey pretty printers in the literature, comparing their expressiveness, optimality, worst-case time complexity, and practical running time. Our evaluation shows that PrettyExpressive is efficient and effective at producing optimal layouts. PrettyExpressive has also seen real-world adoption: it serves as a foundation of a code formatter for Racket.

Keywords

Cite

@article{arxiv.2310.01530,
  title  = {A Pretty Expressive Printer (with Appendices)},
  author = {Sorawee Porncharoenwase and Justin Pombrio and Emina Torlak},
  journal= {arXiv preprint arXiv:2310.01530},
  year   = {2023}
}

Comments

34 pages. This is the full version (with appendices) of the OOPSLA 2023 paper "A Pretty Expressive Printer."

R2 v1 2026-06-28T12:38:45.063Z