ocaml pretty printer (code formatter)
Asked Answered
F

2

15

I am looking for a code formatter or pretty printer for ocaml. Something like gofmt for the go programming language. It should preferably preserve comments.

I am correcting hand-ins and some of the code is formatted in a way that makes it very hard to read.

Falsecard answered 9/10, 2012 at 11:7 Comment(0)
B
18

if you don't care about comments, you can use camlp4:

camlp4 <file> -parser o -printer o > <new-file>

Or you can use external indenter tools, as ocp-indent.

Bargeboard answered 9/10, 2012 at 11:29 Comment(2)
Actually, that seemed to preserve comments. Thank you!Falsecard
You might also want to include the way to do with the revised syntax. I needed it for use with the Camlp4 lexer parser.Capacitance
G
0

These days ocamlformat is recommended and well integrated into dune with dune fmt.

Globose answered 30/9, 2023 at 20:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.