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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 52354BBAF for ; Mon, 26 Jul 2010 17:41:59 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUCAGtJTUxKfVIukGdsb2JhbACDFJxECBUBAQEBCQkMBxEDH7FrO4IQhVUuiFQBAQMFgSGDHXMEiGQ X-IronPort-AV: E=Sophos;i="4.55,261,1278280800"; d="scan'208";a="64432344" Received: from mail-ww0-f46.google.com ([74.125.82.46]) by mail1-smtp-roc.national.inria.fr with ESMTP; 26 Jul 2010 17:41:59 +0200 Received: by wwb18 with SMTP id 18so304096wwb.3 for ; Mon, 26 Jul 2010 08:41:58 -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 :content-transfer-encoding; bh=t9woKpzwg3tXqnuB4tfywjUFZLqpc4IV58EHusX1wc4=; b=pqOoNDrfx2ywQNUtWdKT5IaG1crgtdYw2yqUO2y5U9c+CccpzkoXQg1ez2KCpTIIvU 6RD3QOJen3fnd0OFZliXzwYNIbj3N8r7iDeBDXb7ZAVLBUOb3jkV6f62cP83oOP2Sq8c v7TF/3/7/bRJRhlY6iisShiHNZ6QiSc9kQKTs= 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:content-transfer-encoding; b=jQSmkJEBQem6TNjo16ubdGphDTkUnmT+JUAr6X4/sUXVjzU7palLxxyhLKI4ga0u+c O2ZT0XZTXoNg/DZxJz8t8MJGTrqATQ1I9VYeLpxroVomDLMnuBOzYHc1daVeOCrHROTE Gu4jAezsRLXZyvMDkSfCx6WKXxGETPIBwAmR8= MIME-Version: 1.0 Received: by 10.227.157.13 with SMTP id z13mr7464435wbw.184.1280158918469; Mon, 26 Jul 2010 08:41:58 -0700 (PDT) Received: by 10.216.182.132 with HTTP; Mon, 26 Jul 2010 08:41:58 -0700 (PDT) In-Reply-To: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> References: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> Date: Mon, 26 Jul 2010 17:41:58 +0200 Message-ID: Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax From: Raphael Proust To: Nicolas Pouillard Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 0200,:01 node:01 node:01 camlp:01 ocaml:01 syntax:01 expander:01 inlined:01 nodes:01 26,:98 onclick:98 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) attri= butes *) > > > > (* 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 Camlp4.= What > > I > > have in mind is to use the original Ocaml syntax for the quotation expa= nder. > > 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 to n= ot 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 cha= nging > the meaning of some constructor application and labels for antiquotations= : > > (* 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) attribu= tes *) 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 do= es not (<:smthg< ... >> is already "reserved"). 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$ >> What I basically need is to get an AST with antiquotations and quotations b= eing special nodes. How is this achievable w/o reimplementing a whole grammar? 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? -- _______ Raphael