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 DEE37BBAF for ; Mon, 26 Jul 2010 17:13:22 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUCAG5CTUxKfVIukGdsb2JhbACfVwgVAQEBAQkJDAcRAx+yEIIQhUQuiFQBAQMFhTEEhAg X-IronPort-AV: E=Sophos;i="4.55,261,1278280800"; d="scan'208";a="64430137" Received: from mail-ww0-f46.google.com ([74.125.82.46]) by mail1-smtp-roc.national.inria.fr with ESMTP; 26 Jul 2010 17:13:22 +0200 Received: by wwb18 with SMTP id 18so269300wwb.3 for ; Mon, 26 Jul 2010 08:13:22 -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:in-reply-to:references:mime-version:content-type:content-id; bh=fvs48BFNlXuYLz4joGI2jgHXgz7GezSxKtMP8m5jsSs=; b=a6P31rs8BCXHJQg0PQxLTSUh2RmnLAh4rUkKnSTxEy23bn5rkdY7anXX3SdTSqFf87 fkwFS27a1Ll7ww422TA9JDa5dT3ZxqEXnOpveTCOEMChjqZouN2bsQTLMTUCb7OEolnH ubo3Ei9uscxYZeAE5a1CUD3UrrB/ebHYXYELE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:subject:to:in-reply-to:references:mime-version :content-type:content-id; b=p3SNjQl4S/514D0NRC1xsKxXwsehGDw4JCwLRWGm8HF3cSPNTQUA1y37POY73kYWSI x/1GkwcfmhDdsBwNo9VopRU+QDN7Nds1qLFD0Fa6gS85ZLo4rHaVqL8fnEMK6XQgXjv2 rKALRXan6kcNugxpjjaOXbsyT9IdydbeUmQ/E= Received: by 10.216.231.25 with SMTP id k25mr7582213weq.2.1280157202468; Mon, 26 Jul 2010 08:13:22 -0700 (PDT) Received: from localhost (ks.feydakins.org [91.121.104.209]) by mx.google.com with ESMTPS id p82sm1991964weq.27.2010.07.26.08.13.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 26 Jul 2010 08:13:21 -0700 (PDT) Message-ID: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> Date: Mon, 26 Jul 2010 08:13:21 -0700 (PDT) From: Nicolas Pouillard Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax To: Raphael Proust , caml-list@yquem.inria.fr In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27706.1280157200.1@ks.feydakins.org> X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 0200,:01 syntax:01 runtime:01 abstracted:01 node:01 node:01 camlp:01 ocaml:01 expander:01 parser:01 onclick:98 On Mon, 26 Jul 2010 16:41:46 +0200, Raphael Proust wrote: > Hi all, Hi, > I'm working on a syntax extension as part of an internship in the > Ocsigen team. The aim of the syntax extension is to split the code of a web > application in two separate files: one for the client and one for the > server. A > few transformations are to take place in the process. > > Quotations are to be transformed into client code while antiquotations can > refer > to server side values transmitted to the client at runtime. > > > In order to avoid any XY problems, here is an abstracted and simplified > example > of the expected behavior: > > (* Pre-parsed code: *) > let start = <:on< f $y$ >> in > let html_node = > span ~a:[onclick start] "some text" (* a is used for (html) attributes *) > > (* Server side post-parsed code: *) > let start _arg1 = > "call_closure(some_unique_name," ^ mymarshall _arg1 ")" > in > let html_node = span ~a:[onclick (start y)] "some text" > > (* Client side post-parsed code: *) > let _ = register_closure some_unique_name (fun _arg1 -> f _arg1) > > > > If the example isn't clear enough I can detail it a little bit more. > > > 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 expander. > This would (IIUC) allow me to filter the AST to transform every > antiquotation > found inside the quotation itself. > > I'm not sure this is the ideal way of doing such a thing because of the size > of > the pattern matching in the AST filter. On the other hand, because the > quotation > is supposed to contain valid OCaml code, it seems normal to reuse the > original > parser. If the <:on<...>> contents is valid OCaml syntax I would suggest you to 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 antiquotations: (* Pre-parsed code: *) let start = On (f ~y) in let html_node = span ~a:[onclick start] "some text" (* a is used for (html) attributes *) Have fun, -- Nicolas Pouillard http://nicolaspouillard.fr