caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml IDE (Camlp4 for code formatting)
Date: 21 Jun 2005 12:33:55 +0200	[thread overview]
Message-ID: <rld5qggfsc.fsf@ithif59.inf.tu-dresden.de> (raw)
In-Reply-To: <Pine.LNX.4.58.0506201607470.2193@point>

"Nathaniel J. Gaylinn" <ngaylinn@cs.brown.edu> writes:

   One feature I want my program to have is autoformatting, that is, the
   ability to go through and indent source code for you in some standard way.
   At first glance, OCamlp4 seemed like the way to go for this, but under
   further inspection I'm not sure this is true.
   
   My main problem with OCamlp4 is that it changes the input source code!
   Expressions like "5;;" that are just used for side effect are replaced
   with "let _ = 5;;" which is equivalent, but different code. 

If you are sensitive to these kind of changes then you cannot use
camlp4 to format source code. There are many cases where camlp4
uses the same internal representation for different input. For
example 

  let f a b = ...      and      let f = fun a -> fun b ->
  5 + 6                and      (+) 5 6
  module A(B:S) = ...  and      module A = functor(B:S) -> ...
  begin end            and      ()

Further, superfluous parenthesis and comments are not present in
the ast (i.e. (1,2) is the same as 1,2). (Toplevel comments are
preserved if the printer is able to reopen the input file but
they are lost if you feed camlp4 from a pipe.)

>From that it is clear that camlp4's printer must change the input
in many places.

   I understand why it makes this change, 

Could you explain? (Because I don't understand. "let _ = 5" and
"5" are different internally.)

   On a similar note, is there any reference to the format in which Camlp4
   outputs its syntax tree? 

I don't think so. It is defined in the compiler sources and
probably not for the general public. However, you can define your
own camlp4 printers: Write a module that overwrites
Pcaml.print_implem and load this module into camlp4. The function
that you plug into Pcaml.print_implem has to pattern match on
camlp4's ast, which is defined in mLast.mli. You can use the
constructors from mLast.mli or the quotations from q_MLast. See
the source of pr_o or other pretty printers (like in my ocamlp4
package). 

Bye,

Hendrik


  reply	other threads:[~2005-06-21 10:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 20:08 Nathaniel J. Gaylinn
2005-06-21 10:33 ` Hendrik Tews [this message]
2005-06-21 13:47   ` [Caml-list] " Nathaniel J. Gaylinn
2005-06-21 15:18     ` Hendrik Tews
2005-06-21 18:11       ` David Brown
2005-06-29 14:54         ` [Caml-list] Keyboard interrupt in Windows Nathaniel J. Gaylinn
2005-06-29 16:13           ` Christopher A. Watford

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=rld5qggfsc.fsf@ithif59.inf.tu-dresden.de \
    --to=tews@tcs.inf.tu-dresden.de \
    --cc=caml-list@yquem.inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).