arXiv:2310.01530cs.PL
A Pretty Expressive Printer (with Appendices)
Early discovery. Linked by one identifiable commenter. This paper is outside the main ranking; a mention is not an endorsement.
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$, that is strictly more expressive than all pretty printers in the literature and provably minimizes an optimality objective. Furthermore, the time complexity of $Π_e$ is better than many existing pretty printers. When choosing among different ways to lay out a document, $Π_e$ consults a user-supplied cost factory, which determines the optimality objective, giving $Π_e$ a unique degree of flexibility. We use the Lean theorem prover to verify the correctness (validity and optimality) of $Π_e$, and implement $Π_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.
I think I agree about the testing and labor of complicated translation rules. But it doesn't appear that almost every pretty printer is based on the Wadler algorithm. It seems like MOST of them are not? e.g. clang-format is one of the biggest and best, and it has a model that…
chubotView on HNParent context
OK very interesting! I skimmed over the issue and some of the examples. It does seem like there are at least two schools of thought on the pretty printers -- those influenced by the Wadler pretty printing language (functional style), and those more influenced by go fmt (which…
chubotView on HNParent context