4 ms·
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 strai
by harpocrates 9y ago
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].
[0]: https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
[1]: http://belle.sourceforge.net/doc/hughes95design.pdf
[2]: https://hackage.haskell.org/package/prettyprinter
[3]: https://github.com/harpocrates/language-rust