From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 02700BC75 for ; Mon, 21 Feb 2005 16:22:27 +0100 (CET) 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 j1LFMQ4s014508 for ; Mon, 21 Feb 2005 16:22:26 +0100 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 QAA03971 for ; Mon, 21 Feb 2005 16:22:26 +0100 (MET) Received: from kraid.nerim.net (smtp-101-monday.nerim.net [62.4.16.101]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1LFMPho010141 for ; Mon, 21 Feb 2005 16:22:26 +0100 Received: from localhost (karryall.dnsalias.org [62.4.18.180]) by kraid.nerim.net (Postfix) with ESMTP id 840724192B; Mon, 21 Feb 2005 16:22:23 +0100 (CET) Date: Mon, 21 Feb 2005 16:22:24 +0100 (CET) Message-Id: <20050221.162224.41631465.oandrieu@nerim.net> To: list-caml-list@scientician.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4 with traditional syntax From: Olivier Andrieu In-Reply-To: <20050221125529.GA20112@scientician.net> References: <4219D3E9.80003@barettadeit.com> <20050221125529.GA20112@scientician.net> X-Mailer: Mew version 4.1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4219FCB2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4219FCB1.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 syntax:01 andrieu:01 andrieu:01 ijm:01 baretta:01 wrote:01 hendrik:01 tews:01 wrote:01 baretta:01 expander:01 bypassing:01 expr:01 struct: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: > Bardur Arantsson [Mon, 21 Feb 2005]: > On Mon, Feb 21, 2005 at 01:28:25PM +0100, Alex Baretta wrote: > > > Hendrik Tews wrote: > > >Alex Baretta writes: > > > > There is one more issue with Camlp4: it does not allow for quotations > > > to expand to generic syntactic elements. Often, I use quotations which > > > expand to module definitions. I had to implement my own quotation > > > expander, bypassing the limitations of Camlp4 to achieve this. > > > >I don't quite understand, what's wrong with > > > >let me = <:module_expr< struct $ list of module def's $ end >> > > >in > > > <:str_item< module $some_name$ = $me$ >> > > > We use quotation expanders to embed completely different > > languages, such as SQL, within Ocaml code. Specifically, the SQL > > quotation expander compiles SQL code to an Ocaml module. CamlP4 > > signals an error because quotations are only meant to be used as > > expressions or as patterns, IIRC. > > IIRC quotations can expand to arbitrary ASTs. Only the point of > *use* (ie. substitution) determines which types of ASTs will be > accepted. No, quotations can expand to only expressions or patterns. See the type of a quotation expander in quotation.mli : type expander = | ExStr of (bool -> string -> string) | ExAst of ((string -> MLast.expr) * (string -> MLast.patt)) As Alex mentionned, ocpp expands quotations everywhere (but only deals with string-expanding quotations, not the AST ones), so it can be used to generate structure items (module elements). > Of course, if you're generating things like module interfaces and > implementations, you'll need to generate them side by side since > there is no "combined module interface+implementation" AST node > type. The camlp4 AST does have this kind of nodes, as Martin mentionned. You can use : # fun a b -> <:str_item< declare $a$ ; $b$ ; end >> ;; - : MLast.str_item -> MLast.str_item -> MLast.str_item = or : # fun l -> <:str_item< declare $list:l$ end >> ;; - : MLast.str_item list -> MLast.str_item = -- Olivier