From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 2B2EABBFB for ; Tue, 21 Jun 2005 12:34:00 +0200 (CEST) Received: from tcs.inf.tu-dresden.de (tcs.inf.tu-dresden.de [141.76.75.101]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5LAXxU5018252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 21 Jun 2005 12:33:59 +0200 Received: from ithif59.inf.tu-dresden.de (ithif59 [141.76.75.59]) by tcs.inf.tu-dresden.de (8.12.9/8.12.9) with ESMTP id j5LAXuxA018375 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 21 Jun 2005 12:33:59 +0200 (MET DST) Received: from tews by ithif59.inf.tu-dresden.de with local (Exim 4.50) id 1Dkg4p-0005RM-R5 for caml-list@yquem.inria.fr; Tue, 21 Jun 2005 12:33:55 +0200 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml IDE (Camlp4 for code formatting) References: From: Hendrik Tews Date: 21 Jun 2005 12:33:55 +0200 In-Reply-To: Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) at tcs.inf.tu-dresden.de X-Miltered: at nez-perce with ID 42B7ED17.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 hendrik:01 tews:01 tews:01 functor:01 toplevel:01 syntax:01 compiler:01 pcaml:01 pcaml:01 mlast:01 mli:01 constructors:01 mlast:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: "Nathaniel J. Gaylinn" 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