A Pretty Expressive Printer

Proceedings of the ACM on Programming Languages(2023)

引用 0|浏览8
暂无评分
摘要
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, 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 Pi(e) is better than many existing pretty printers. When choosing among different ways to lay out a document, Pi(e) consults a user-supplied cost factory, which determines the optimality objective, giving Pi(e) a unique degree of flexibility. We use the Lean theorem prover to verify the correctness (validity and optimality) of Pi(e), and implement 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.
更多
查看译文
关键词
printer
AI 理解论文
溯源树
样例
生成溯源树,研究论文发展脉络
Chat Paper
正在生成论文摘要