chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Source code formatter?


From: Lassi Kortela
Subject: Re: Source code formatter?
Date: Mon, 11 Jan 2021 17:07:22 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.6.0

The problem with pretty printer is that it is not designed for source:
it does not keep comments and blank lines.

+1

Scheme reader that preserves them:

- https://github.com/weinholt/laesare

Work-in-progress formatters:

- https://github.com/paines/scmfmt (uses Chicken pretty printer)

- https://github.com/lispunion/code-formatter

Chez Scheme, Gambit, Gauche, Chibi-Scheme also ship a pretty-printer.

At the moment, most people probably use indent-region in Emacs. Emacs can also run in batch mode. There's probably something similar for Vim.

If any one feels like solving the problem for real, I'm happy to advise. This is the outline:

- Expand a reader like laesare to cover all the variants of S-expression syntax (Scheme, CL, Emacs Lisp, Clojure are very similar; no sense in having a different algorithm for each).

- Add a matching printer by consulting "the literature". Marc Feeley of Gambit has written a popular pretty-printer. Wadler has written a paper from first principles: <http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf>.

- A good pretty printer should automatically figure out where to put line breaks, joining and splitting lines of code as needed. This is by far the hardest part of pretty-printing; naive approaches are susceptible to combinatorial explosion.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]