From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id BFA3FBC6B for ; Thu, 26 Jul 2007 10:44:06 +0200 (CEST) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.178]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6Q8i4dJ018934 for ; Thu, 26 Jul 2007 10:44:06 +0200 Received: by wa-out-1112.google.com with SMTP id k17so219864waf for ; Thu, 26 Jul 2007 01:44:04 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=URpzWBhg4vpb1WxS2yVX0LNji+atuDzxU4Fkjf6+jwJfAsHjXwA5l/dlY8CgR7mTfP6CshygEjT+7MQVKMjVmZhkxiB02mbsxjhrt7RkUYzw0w8HB3xCJKF0m49/cTWnEO8RyxaOOkokqrdBtz6z7PHraD5kyMwVFVwfJLwYI/o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gqU37WGkypTurzqFLQJTr/H9gaooKNIVE484dP2kcRho7ZpAznQImyicoHr4YFovIpY6yP0qD/xaqb9FzTtImepVMed9+NYMj4fMmxgmcEhBD9sIqedD0eWyV9WUNMmNX2aH39ttstJEmQsAtwUmtAmSRr23MuAl5GD25+iOby4= Received: by 10.114.93.17 with SMTP id q17mr1503198wab.1185439444119; Thu, 26 Jul 2007 01:44:04 -0700 (PDT) Received: by 10.114.181.8 with HTTP; Thu, 26 Jul 2007 01:44:04 -0700 (PDT) Message-ID: Date: Thu, 26 Jul 2007 10:44:04 +0200 From: "Nicolas Pouillard" To: "Harrison, John R" Subject: Re: [Caml-list] Equivalent of Quotation.ExStr in new camlp4? Cc: caml-list@yquem.inria.fr In-Reply-To: <509223F0BF55E74FA1247D17207E7A0C01B120CA@orsmsx419.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <509223F0BF55E74FA1247D17207E7A0C01B120CA@orsmsx419.amr.corp.intel.com> X-j-chkmail-Score: MSGID : 46A85ED5.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 46A85ED5.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 parser:01 expander:01 concretely:01 expander:01 instanciate:01 ocaml:01 parser:01 camlp:01 expr:01 expr:01 syntax:01 syntax:01 ocamlc:01 -pp:01 On 7/25/07, Harrison, John R wrote: > | No ExStr is no more supported. But you can do it your self by calling > | the parser on your string if you really don't want switch to an AST > | based quotation expander. > > OK, that's fine. But how do I do that? Concretely, this is what I had > before, so what should I have now? > > Quotation.add "" (Quotation.ExStr (fun x -> quotexpander));; > > I don't mind in principle writing an AST-producing expander, but at the > moment the priority is to get my code working in 3.10 with minimal > expenditure of effort. > You can instanciate an OCaml parser that way: $ cat ex_str.mlmodule Caml = Camlp4OCamlParser.Make (Camlp4OCamlRevisedParser.Make (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));; let quotexpander str = "[1; 2; 3]" (* ... do some real code on str *) let patt_quotexpander loc _loc_name_opt str = Gram.parse_string Caml.patt loc (quotexpander str) let expr_quotexpander loc _loc_name_opt str = Gram.parse_string Caml.expr loc (quotexpander str) let str_item_quotexpander loc loc_name_opt str = <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >> let () = Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag expr_quotexpander; Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag str_item_quotexpander; Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag patt_quotexpander $ ocamlc -pp camlp4of -I +camlp4 -c ex_str.ml $ camlp4o ./ex_str.cmo -str '<<>>;;' HTH -- Nicolas Pouillard