Open xurtis opened 7 years ago
There is much prior art in s-expression pretty printing, though most of it focuses specifically on rules for Lisp-like languages. If that's your target here, you probably want to implement (something like) the X3J13 pretty-printing style or mimic the Guile or Racket pretty printers.
In summary, the former, tightly-braced style makes a good deal more sense as a starting point, but adding behaviours depending on symbols would be useful. Symbols should also always be tightly-braced before and after, as dangling parens or loose parens tend to look bad in the context of Lisps, so:
((blah blah blah)
(blah
(blah blah blah))
blah)
Let me propose a few rules.
First, we classify every value as either code or data in an implicit manner.
Secondly, we classify the depth of each list as such:
Int
, Float
, and String
all have a depth of 0.The hard part after this is using this information to know when to indent an break lines...
Hi there 👋 I'm a few years late to the party, but was wondering if you intended to merge that pretty-print
branch? I've been looking for a Rust sexp pretty-printer and this looks like exactly what I need :)
Currently, all output is through display and printed on a single line. It'd be good to have a pretty printer that nicely formats the output using the following rules:
Condensed format with tight bracing
Sparse formatting with loose bracing