From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 2FECEBBAF for ; Tue, 27 Jul 2010 09:57:28 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtYBACsuTkxKfVIukGdsb2JhbACDFJxJCBUBAQEBCQkMBxEDH6ZCiEA7ghCGOy6IVAEBAwWBIYMdcwSIaA X-IronPort-AV: E=Sophos;i="4.55,266,1278280800"; d="scan'208";a="66975958" Received: from mail-ww0-f46.google.com ([74.125.82.46]) by mail4-smtp-sop.national.inria.fr with ESMTP; 27 Jul 2010 09:57:27 +0200 Received: by wwb18 with SMTP id 18so917127wwb.3 for ; Tue, 27 Jul 2010 00:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=rP0mqmIhmkJYy4TiEXiEJ7w96ssDwm94eCymFhzmGk0=; b=iETrf1MFAsSD3E/v1gZLalvhfIxk0oEA6sbYtIw2vJd54uBdKv5Bvt22D2qsIvPiYq jfkPotJEVMT5Utov2jCoj0gJ2sq+/LmQVSMGNgyg1nX/EYLwpZaTLoGwXqxhSM7E2+cJ WMOcNqz8KrqFZisRUhn8EdV0RWGhl2GTdQaV4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=gpu5nzKkrdIhOKRcRaTueCQKjBNGj0nRNECT79QZ8SKfILLv3qQYZzPaMiWsUlYiJa 6P4fzFOYWp57XuG9lyBOmfaiIAycHjkkWMJ3ILr/CqIL2TOUtwmYXL4E59tTEq73Lmk7 11zvveXrB4vhopDnLb6aa9X6THPy4wT0UcsUs= MIME-Version: 1.0 Received: by 10.227.7.94 with SMTP id c30mr8528439wbc.45.1280217447116; Tue, 27 Jul 2010 00:57:27 -0700 (PDT) Received: by 10.216.182.132 with HTTP; Tue, 27 Jul 2010 00:57:27 -0700 (PDT) In-Reply-To: References: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> Date: Tue, 27 Jul 2010 09:57:27 +0200 Message-ID: Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax From: Raphael Proust To: Jake Donham Cc: Nicolas Pouillard , caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 nodes:01 node:01 parser:01 parser:01 camlp:01 implements:01 ocaml:01 26,:98 26,:98 blog:98 wrote:01 On Mon, Jul 26, 2010 at 6:30 PM, Jake Donham wrote: > On Mon, Jul 26, 2010 at 8:41 AM, Raphael Proust wrote: >> What I basically need is to get an AST with antiquotations and quotations being >> special nodes. How is this achievable w/o reimplementing a whole grammar? > > There is already a special node for antiquotations, but not > quotations; see below. > >> The alternative solution is to use raw strings, to find antiquotation marks, to >> split the string and to reinject it in the different files. Is there a way to >> keep precise _loc information this way? > > [...] > > I'm not sure what syntactic problems Nicolas suggests you would run > into by reusing the existing parser and quotation mechanism. But it > might be a bit hairy to implement. One issue is that you can't just > drop antiquotations anywhere; where they can appear (and with what > tag) is given by the parser. If you want to go in this direction, the > place to start would be Camlp4QuotationCommon.ml, which implements > OCaml AST quotations / antiquotations. You can see there that you can > parse starting at arbitrary non-terminals, and you can filter the > OCaml AST without a giant pattern match using the Ast.map object. I'll read the Camlp4QuotationCommon source code and try to have something like {:on{ f $y$ }} working. Thanks for the answer and thanks for the Camlp4 blog post series, it helped me a lot to get the first version of my extension working! -- _______ Raphael