Crate pomelo_fmt
source ·Expand description
Code formatting for SML.
This is intended for use internally within pomelo
.
Beware, this currently discards comments. Not suitable for real code!
This is intended to format the pretty-printed HIR, which is itself valid SML.
Currently, only dealing with the Core language, as pomelo_parse
does not know how to handle modules.
Status
- format expressions (mostly done)
- format patterns
- format declarations
- format types
- deal with comments and other trivia.. maybe need to do a better job of attaching trivia to nodes in parsing?
Resources
-
“Prettyprinting”, Derek C. Oppen (1980)
-
“A prettier printer”, Phillip Wadler (2003)
-
“Pretty Printing with Lazy Dequeues”, Olaf Chitil (2005)
-
prettyplease
, an implementation of Oppen’s algorithm in Rust by David Tolnay
The code here is based on the imperative algorithm from the Oppen paper. The other papers give pure functional versions of the pretty printing algorithm – I found those a bit easier to understand than the Oppen paper but the imperative algorithm should be easier to implement efficiently in Rust.
David Tolnay’s prettyplease
crate is a nice implementation of Oppen’s algorithm in Rust.
I mainly worked off of the description in Oppen’s paper, but I peeked at prettyplease
a couple of times to help iron out some of the bugs in my implementation.