Re:The Hardest Program I've Ever Written (2015)
by harpocrates on Monday August 21, 2017 @03:30PM
(#15067094)
Pretty-printing is tough. That said, please don't reinvent the wheel. There is research that has gone into this that should make most of this stuff pretty straightforward. I personally recommend Wadler's "A Prettier Printer" [0] (although credit goes to Hughes for laying a lot of the groundwork [1]). It too uses an IR and has several possible heuristics for rendering.
I've been using an implementation of it [2] with a lot of success for pretty printing Rust code [3].
I've been using an implementation of it [2] with a lot of success for pretty printing Rust code [3].