Pretty Printing Source Code
Building a pretty printer even for a specific language is surprisingly difficult. It’s even harder to build a general pretty printing engine. For an interesting research framework, take a look at the pretty printing language called BOX described by Merijn de Jonge in Pretty-Printing for Software Reengineering [De 02]. General pretty printers require some serious voodoo, and language-specific pretty printers tend to be messy ad hoc code blobs. Let’s see whether we can design a more formal language-specific pretty printer as a compromise.
We can make the problem dramatically easier if we relax it a little bit. Most pretty printers consider the right column a “do not exceed” hard limit. They must wrap everything before ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access