CatalaLang / catala

Programming language for literate programming law specification
https://catala-lang.org
Apache License 2.0
1.98k stars 77 forks source link

Formatter for Catala code #255

Open EmileRolley opened 2 years ago

EmileRolley commented 2 years ago

As suggered in #252, adding a formatter to the Catala toolkit could be a great improvement for both the developer and the reviewer experience. Catala being a literate programming language, having a good readability of the code is essential.

Proposals

  1. A first step could consist of the addition of a new Format backend using the surface AST of the compiler.
  2. A second one could be done by implementing a standalone program using for instance Tree-sitter in order to take advantage of the incremental parsing.
AltGr commented 2 years ago

Additionally, this could allow automatic translation from one Catala dialect to another, e.g. French to Engish.

denismerigoux commented 2 years ago

Indeed, except for variable names...

AltGr commented 1 year ago

Update: it's still in progress, but I have a working tree-sitter parser at https://github.com/AltGr/tree-sitter-catala

and the included catala.el file contains an emacs mode (for emacs 29+) that can do automatic indentation based on it.

AltGr commented 12 months ago

The easiest way for formatting Catala at this point will be to use https://github.com/AltGr/tree-sitter-catala and https://github.com/tweag/topiary