infolab-csail / lispify

Lispify converts Python objects into Lisp-like encoded strings that are interpretable in Common Lisp.
MIT License
0 stars 0 forks source link

Add a basic pretty-printing capability to produce human-readable output #8

Open sfelshin opened 7 years ago

sfelshin commented 7 years ago

Sometimes lispify is used to create lisp forms that will be read (and perhaps edited) by humans, in which case it is helpful to have reasonably short lines with good indentation. E.g., it's hard for a human to read this:

(:attribute (:end_time "00:04:04.400000" :start_time "00:03:42.030000" :title "Introduction to 'Modernity in Interwar Japan'") :cls "edx-video" :sentence-annotation "The Japanese knew about steam-driven warships but hadn't seen them before the 'Black Ships' arrived." :source "manual")

and much easier to read this:

(:attribute (:end_time "00:04:04.400000"
         :start_time "00:03:42.030000"
         :title "Introduction to 'Modernity in Interwar Japan'")
 :cls "edx-video"
 :sentence-annotation "The Japanese knew about steam-driven warships but hadn't seen them before the 'Black Ships' arrived."
 :source "manual")

(Most elements of the form fit nicely and the one excessively long element doesn't affect the readability of the rest of the form.)

Add a pretty printing capability to lispify. A sophisticated implementation of line-breaking and indentation is pretty hard, but isn't necessary. It shouldn't be too difficult to implement something slightly better than a naïve implementation (see below)—something that balances adequate line-breaking with acceptable implementation cost.

Suggested operation: