From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Mihamina Rakotomandimby <mihamina@rktmb.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Format OCaml Code
Date: Fri, 23 Dec 2011 09:51:20 +0100 [thread overview]
Message-ID: <CAPFanBENrfvHh_qid07akjhm0KgSz4RAKCwwcGFhZvp08O2q2A@mail.gmail.com> (raw)
In-Reply-To: <4EF43609.6040609@rktmb.org>
Camlp4 parses Ocaml source, and can reprint it. You can't customize
the output much, it's defined by the pretty-printer (but you could
write your own pretty-printer), and it probably doesn't correspond to
your own OCaml style. If you're only looking for a way to normalize
indentation, you may be happy with that.
camlp4o file.ml (* outputs in the console *)
camlp4o file.ml -o output.ml
Note that piping/redirection `camlp4o file.ml > foo` doesn't work as
camlp4o sends a marshalled AST by default.
An issue with camlp4 is that it can sometimes move comments a bit: the
placement of comments in the reformatted source is approximative *with
respect to whitespace* (you sometimes have a blank inserted between a
phrase and the comment). That is not really an issue for the human
reader, but it tends to confuse `ocamldoc`, which relies on whitespace
heuristics to know which phrase a comment documents. You should think
twice if you wish to use both camlp4 and ocamldoc at the same time.
If you wanted to write your own pretty-printer (as a Camlp4 printer,
or based on your own or another parser), you could be interested in:
- The [Pprint] module of François Pottier, an interesting adaptation
of Daan Leijen's Haskell PPrint library
http://pauillac.inria.fr/~fpottier/
- The [easy-format] library of Martin Jambon
http://martin.jambon.free.fr/easy-format.html
- The [Format] module of the standard library
http://caml.inria.fr/resources/doc/guides/format.en.html
I have only used Format and Pprint, and prefer Pprint (simpler to
understand and use).
On Fri, Dec 23, 2011 at 9:04 AM, Mihamina Rakotomandimby
<mihamina@rktmb.org> wrote:
> On 12/23/2011 10:57 AM, haihao shen wrote:
>>
>> Hi All,
>>
>> Does anyone know whether there is some tools or scripts to format ocaml
>> code in a unified format?
>
>
> If you mean having a "good" indentation, opening it in Emacs+tuareg-mode
> then indenting will work fine.
>
> Note that it's a file by file way and it doesn not split uselessly long
> lines to shorter ones: just indentation. Or I dont know how to fully use
> tuareg-mode ;-).
>
> For a large set of files, I don't know how to ease the work.
>
>
> --
> RMA.
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
next prev parent reply other threads:[~2011-12-23 8:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-23 7:57 haihao shen
2011-12-23 8:04 ` Mihamina Rakotomandimby
2011-12-23 8:51 ` Gabriel Scherer [this message]
2011-12-23 12:27 ` rixed
2011-12-23 12:49 ` Jérémie Dimino
2011-12-23 17:01 ` Jérémie Dimino
2011-12-24 3:48 ` Francois¡¡Charles Matthieu¡¡Berenger
2011-12-24 8:35 ` Jun Furuse
2011-12-24 9:03 ` haihao shen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPFanBENrfvHh_qid07akjhm0KgSz4RAKCwwcGFhZvp08O2q2A@mail.gmail.com \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=mihamina@rktmb.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox