From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 81341BC57 for ; Fri, 6 Aug 2010 23:25:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0DAE4aXEyNTDBjgWdsb2JhbACTW4xvFQEBFiIixkmFOgSJNw X-IronPort-AV: E=Sophos;i="4.55,331,1278280800"; d="scan'208";a="56824397" Received: from os.inf.tu-dresden.de ([141.76.48.99]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Aug 2010 23:25:24 +0200 Received: from [2002:8d4c:3001:48:222:68ff:fe19:71d] (helo=blau.inf.tu-dresden.de) by os.inf.tu-dresden.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) id 1OhUPr-0006dS-AI for caml-list@inria.fr; Fri, 06 Aug 2010 23:25:23 +0200 Received: from tews by blau.inf.tu-dresden.de with local (Exim 4.72) (envelope-from ) id 1OhUPq-0002bn-Ey for caml-list@inria.fr; Fri, 06 Aug 2010 23:25:22 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19548.32194.301525.322135@blau.inf.tu-dresden.de> Date: Fri, 6 Aug 2010 23:25:22 +0200 To: caml-list@inria.fr Subject: Quotations and the functorial camlp4 interface X-Mailer: VM 8.1.0 under 23.1.1 (i486-pc-linux-gnu) From: Hendrik Tews X-Spam: no; 0.00; camlp:01 hendrik:01 tews:01 tews:01 camlp:01 parsers:01 syntax:01 syntaxes:01 functor:01 syntax:01 parses:01 parses:01 sig:01 functor:01 struct:01 Hi, Camlp4 parsers have a functorial interface (eg. Camlp4OCamlParser.Make), which makes it possible to build two camlp4 syntax modules in one application that parse different syntaxes. How can I add quotation support to such camlp4 parsing modules? [Unfortunately, there is no functor Camlp4OCamlRevisedQuotationExpander.Make.] More in detail: Assume I obtained two camlp4 syntax modules SO and SR, such that SO parses the orginal syntax and SR parses the revised syntax. I now want to add quotation support to both SO and SR. Following Camlp4OCamlRevisedQuotationExpander I do module PreCast = Camlp4.PreCast module type Camlp4Syntax = Camlp4.Sig.Camlp4Syntax with module Loc = PreCast.Loc and module Ast = PreCast.Ast module Make (HostSyntax : Camlp4Syntax) (MakeQuotationSyntax : functor(EmptySyntax : Camlp4Syntax) -> Camlp4Syntax) = struct module Gram = PreCast.MakeGram(PreCast.Lexer) module EmptySyntax = Camlp4.OCamlInitSyntax.Make(PreCast.Ast)(Gram)(HostSyntax.Quotation) module QuotationSyntax = MakeQuotationSyntax(EmptySyntax) module X = Camlp4QuotationCommon.Make(QuotationSyntax)(HostSyntax.AntiquotSyntax) end now I can add the quotation support to SO and SR with let module M = Make(SO)(Camlp4OCamlRevisedParser.Make) in let module M = Make(SR)(Camlp4OCamlRevisedParser.Make) in () Could anybody comment on this? The solution above is based on the following observations: 1. Camlp4QuotationCommon.Make(QuotationSyntax)(..) installs the parser in QuotationSyntax as (various) quotation expander(s) in QS.Quotation. This has only an effect on HostSyntax if the references that Camlp4QuotationCommon.Make mutates are actually identical in QuotationSyntax and HostSyntax. 2. The two MakeQuotationSyntax candidates Camlp4OCamlRevisedParser.Make and Camlp4OCamlParser.Make do only mutate the grammar entries in their argument modules. Therefore one always has to create new EmptySyntax'es but can reuse all the rest (especially Lexer, Ast and Loc) from Camlp4.PreCast. 3. The functor Camlp4QuotationExpander.Make cannot be used instead of Make above, because it creates reflective grammers (where the host syntax and the quotation syntax are identical). Are these observations right? Finally I have the following question: 4. Why does Camlp4OCamlRevisedQuotationExpander generate a new grammar module Gram and does not reuse Camlp4.PreCast.Gram? Can the latter be changed by some syntax extension? [This post actually belongs to the thread http://caml.inria.fr/pub/ml-archives/caml-list/2008/04/9d32f304eec6328db7ce857673842760.en.html, which discusses how to make those functors SO and SR.] Bye, Hendrik Tews