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 78EAFBBAF for ; Mon, 26 Jul 2010 18:27:46 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUCADNUTUxKfVK0kGdsb2JhbACDFJxECBUBAQEBCQkMBxEDH7ImO4IQhWIuiFQBAQMFgSGDHXMEhAg X-IronPort-AV: E=Sophos;i="4.55,262,1278280800"; d="scan'208";a="66954549" Received: from mail-wy0-f180.google.com ([74.125.82.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 26 Jul 2010 18:27:46 +0200 Received: by wyb33 with SMTP id 33so2761777wyb.39 for ; Mon, 26 Jul 2010 09:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:subject :to:cc:in-reply-to:references:mime-version:content-type:content-id :content-transfer-encoding; bh=Hfiv/lKcOyUfqTySDuXeoNBaLEn0NVQQwBISzR9RrvU=; b=lWZiF/fFM6/wyeuXNJtCh+AEcmBAXhJldMzV9mrHWBZmh8XyXb1Ev9fBMB8bAKgRBw CSRYzqIj/LtTIktmLrxRWw8tKTUySjjPdvEa6xvrkq058qvkdrXhvzCY3hrmcbXI9eZ/ EWLqcuS9aujBKKxAv39YiMTdKwTBfHFfKI6xU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:subject:to:cc:in-reply-to:references :mime-version:content-type:content-id:content-transfer-encoding; b=sURIwNgIUOM7HR5cpWYs4VJPPZqOK53h/psA2qDvPGtycbQyqTltwXn1X9mEWEE3Ub H63H7ZaGtsp5aCzQlysDKNSfFlA1vWH11q8dtJOVoDYqQvj+exl2aRe6w19Y42UPp+oT EbLL3+y5/duyU8c2AxS1/lxT9lxpHzF9JfKkU= Received: by 10.216.164.141 with SMTP id c13mr7586289wel.83.1280161665838; Mon, 26 Jul 2010 09:27:45 -0700 (PDT) Received: from localhost (ks.feydakins.org [91.121.104.209]) by mx.google.com with ESMTPS id n17sm2040149weq.30.2010.07.26.09.27.45 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 26 Jul 2010 09:27:45 -0700 (PDT) Message-ID: <4c4db781.91e8d80a.69cf.5c7c@mx.google.com> Date: Mon, 26 Jul 2010 09:27:45 -0700 (PDT) From: Nicolas Pouillard Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax To: Raphael Proust Cc: caml-list@yquem.inria.fr In-Reply-To: References: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <31154.1280161664.1@ks.feydakins.org> Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 0200,:01 0200,:01 node:01 node:01 camlp:01 ocaml:01 syntax:01 expander:01 clashes:01 inlined:01 nodes:01 On Mon, 26 Jul 2010 17:41:58 +0200, Raphael Proust w= rote: > On Mon, Jul 26, 2010 at 5:13 PM, Nicolas Pouillard > wrote: > > On Mon, 26 Jul 2010 16:41:46 +0200, Raphael Proust wrote: > > > Hi all, > > Hi, > > > > > [...] > > > > > > (* Pre-parsed code: *) > > > let start =3D <:on< f $y$ >> in > > > let html_node =3D > > > =C2=A0span ~a:[onclick start] "some text" (* a is used for (html) at= tributes *) > > > > > > (* Server side post-parsed code: *) > > > let start _arg1 =3D > > > =C2=A0"call_closure(some_unique_name," ^ mymarshall _arg1 ")" > > > in > > > let html_node =3D span ~a:[onclick (start y)] "some text" > > > > > > (* Client side post-parsed code: *) > > > let _ =3D register_closure some_unique_name (fun _arg1 -> f _arg1) > > > > > > > > > I'm unsure of what is the standard way of doing such a thing in Caml= p4. What > > > I > > > have in mind is to use the original Ocaml syntax for the quotation e= xpander. > > > This would (IIUC) allow me to filter the AST to transform every > > > antiquotation > > > found inside the quotation itself. > > > > > > [...] > > > > If the <:on<...>> contents is valid OCaml syntax I would suggest you t= o not go > > in the quotations direction. You will avoid a ton of syntactic issues. > > > > What I suggest you is to directly use camlp4 filters, for instance by = changing > > the meaning of some constructor application and labels for antiquotati= ons: > > > > (* Pre-parsed code: *) > > let start =3D On (f ~y) in > > let html_node =3D > > =C2=A0span ~a:[onclick start] "some text" (* a is used for (html) attr= ibutes *) > = > I'd rather not use a constructor because it imposes a strong limitation = on the > user (it basically reserves a keyword) whereas the <:on< ... >> solution= does > not (<:smthg< ... >> is already "reserved"). You still qualify it if you want to avoid clashes: MyModule.On > And labeling antiquotations is far from ideal since it prevents complex > expressions from being inlined. You basically need to write: > let y =3D h a in > let z =3D g x z in > On (f ~y ~z) > instead of: > <:on< f $h a$ $g x z$ >> Nothing prevents you to reserve another syntax for going back to plain OCa= ml code. > What I basically need is to get an AST with antiquotations and quotation= s being > special nodes. How is this achievable w/o reimplementing a whole grammar= ? Doing this amounts to making the almost the same thing than Camlp4OCamlOriginalQuotationExpander but with some filtering code. > The alternative solution is to use raw strings, to find antiquotation ma= rks, to > split the string and to reinject it in the different files. Is there a w= ay to > keep precise _loc information this way? Yes _loc would be hard to preserve this way. -- = Nicolas Pouillard http://nicolaspouillard.fr