From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 7D19ABC48 for ; Tue, 19 Apr 2005 23:52:05 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j3JLq4bE000748 for ; Tue, 19 Apr 2005 23:52:05 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA29532 for ; Tue, 19 Apr 2005 23:52:04 +0200 (MET DST) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j3JLq3Kr008046 for ; Tue, 19 Apr 2005 23:52:04 +0200 Received: from frontend3.messagingengine.com (frontend3.internal [10.202.2.152]) by frontend1.messagingengine.com (Postfix) with ESMTP id 3B9A3C75A88; Tue, 19 Apr 2005 17:52:02 -0400 (EDT) X-Sasl-enc: tXfmuwTlysoteFE6qfmmJTGTWibnQ1SwEM6Kj+opZEFZ4MJeRruyYNyc4UT1 1113947522 Received: from [172.16.112.115] (burnham.ljcrf.edu [192.231.106.2]) by frontend3.messagingengine.com (Postfix) with ESMTP id 4245466; Tue, 19 Apr 2005 17:52:01 -0400 (EDT) Date: Tue, 19 Apr 2005 14:51:56 -0700 (PDT) From: Martin Jambon X-X-Sender: martin@localhost To: Markus Mottl Cc: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4: extending syntax of record definitions In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 42657D85.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42657D83.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 syntax:01 markus:01 mottl:01 grammar:01 syntax:01 minor:01 grammar:01 ocaml:01 ocaml:01 uncommented:01 ...:98 wrote:01 wrote:01 rewrite:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Tue, 19 Apr 2005, Markus Mottl wrote: > On 4/18/05, Martin Jambon wrote: > > My experience in that field tells me that the more you try to extend > > existing syntaxic constructs, the more difficult it is. > > > > You have to look at pa_o.ml from the Camlp4 distribution first, and see if > > the rule corresponding to record definitions is public (belongs to > > a "GLOBAL" entry) or not. > > I had already copied half of the grammar to add my extension, but then > I thought that this is insane. I couldn't believe that there is no > simpler way of doing that, but obviously there really isn't. > > > If the entry that contains this rule is public, then you can delete the > > rule and rewrite it, and everything is fine. > > Otherwise, you have to improvise. Which is the case here: the type_kind > > entry is not visible from outside. > > Right. I had to essentially copy everything from "type_declaration" > downwards, which is quite a lot. Besides from redistributing a modified pa_o.ml or a program that patches pa_o.ml and makes every entry public, I don't see any solution. There would probably be problems for syntax extensions that are supposed to work for both the regular and the revised syntax (I don't use the revised syntax myself so it's only a problem if I want to please the users of the revised syntax...). Also, the minor grammar entries in pa_o.ml happen to change from one version of OCaml/Camlp4 to another, so it would be (even more) difficult to maintain compatibility across various versions of OCaml if a syntax extension had to rely on them. I would love to know the point of view of the developers of Camlp4... > > One reasonable solution, in general, if you have a limited time or budget, > > is to extend str_item (items of a module implementation) with > > a whole new syntax. Something like: > > I don't think that this is necessary, because it's only the type > declaration I want to change, not the syntax for record expressions. > The user must call the validation functions manually on his values. I see. > > You can look at this example (uncommented), which is very similar: > > http://martin.jambon.free.fr/extend-ocaml-syntax.html#types > > Thanks, that's a very nice tutorial on Camlp4. Maybe it could be added > to the documentation index for OCaml at INRIA? Thanks. I thought I should fill the gaps first (mainly English sentences). Martin -- Martin Jambon, PhD http://martin.jambon.free.fr