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

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.

Modules

buffer 🔒
Buffer implementation for Oppen algorithm.
dec 🔒
expr 🔒
pat 🔒
printer 🔒
Oppen-style pretty printer.
ty 🔒
util 🔒
Utility functions for working with whitespace, comments, etc.

Constants

INDENT 🔒

Traits

Printable 🔒

Functions

Pretty print the AST.