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 4518BBBAF for ; Mon, 26 Jul 2010 17:40:39 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUCAKZJTUxKfVK0kGdsb2JhbACSaYxvCBUBAQEBCQkMBxEDH7ImghCFVS6IVAEBAwWFMQSIZA X-IronPort-AV: E=Sophos;i="4.55,261,1278280800"; d="scan'208";a="66951834" Received: from mail-wy0-f180.google.com ([74.125.82.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 26 Jul 2010 17:40:38 +0200 Received: by wyb33 with SMTP id 33so2699818wyb.39 for ; Mon, 26 Jul 2010 08:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:references:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:x-mailer :mime-version:subject:date:cc; bh=2uCRcN0sgqvK0bu4mL9JJiG9Z9DUfLISjf+SK1UhSDg=; b=ErY/5YCWLHDeJ7h8HpS7euEqz/Wozxb6e5dMtcl3DVe7H8VEiPqbdQ50C9mH/E4nmm YZIHwSliTLtgd5fLKdHyP2xj2gY7UCo57SuD6okwtD8+c3Lq436MdP+LVVPcX0/WRJ7+ bXJ2LTEGxL4UxOkA/cmhRq+oA+fmKKj1SrDdM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:mime-version:subject:date:cc; b=l8WfoOG4PQi6Cd51W4p+MNFs4S6BEI9vmmAoVpMZ1QA1b18o3mZbtIbFBifEgbufV2 We+afkJdutQ3dQw6oGsHtiLMrAXz2RjHvwt6TDvJoE65Ypzk6BvtXL33CbQc+Ft7QRM2 57NJG5AQ63Z1mhBpzukE4Q+0j1wiatvb19IB0= Received: by 10.227.72.139 with SMTP id m11mr7555865wbj.30.1280158837599; Mon, 26 Jul 2010 08:40:37 -0700 (PDT) Received: from [10.10.30.21] ([83.44.137.176]) by mx.google.com with ESMTPS id u32sm2011423weq.11.2010.07.26.08.40.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 26 Jul 2010 08:40:36 -0700 (PDT) References: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> Message-Id: <9828C252-847B-4921-902D-376412CD7F16@gmail.com> From: Joel Reymont To: Nicolas Pouillard In-Reply-To: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Mailer: iPad Mail (7B405) Mime-Version: 1.0 (iPad Mail 7B405) Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax Date: Mon, 26 Jul 2010 16:41:16 +0100 Cc: Raphael Proust , "caml-list@yquem.inria.fr" X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 ocaml:01 syntax:01 camlp:01 parser:01 parser:01 0200,:01 runtime:01 abstracted:01 node:01 node:01 expander:01 What if the quotation is not valid OCaml syntax, e.g. C#, and a Camlp4 = parser for it exists? How would I tie it all together to parse the quotation, plug in = antiquotations and end up with the custom AST that my parser outputs? Thanks, Joel Sent from my iPad On Jul 26, 2010, at 16:13, Nicolas Pouillard = wrote: > On Mon, 26 Jul 2010 16:41:46 +0200, Raphael Proust = wrote: >> Hi all, >=20 > Hi, >=20 >> 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. >>=20 >> Quotations are to be transformed into client code while = antiquotations can >> refer >> to server side values transmitted to the client at runtime. >>=20 >>=20 >> In order to avoid any XY problems, here is an abstracted and = simplified >> example >> of the expected behavior: >>=20 >> (* Pre-parsed code: *) >> let start =3D <:on< f $y$ >> in >> let html_node =3D >> span ~a:[onclick start] "some text" (* a is used for (html) = attributes *) >>=20 >> (* Server side post-parsed code: *) >> let start _arg1 =3D >> "call_closure(some_unique_name," ^ mymarshall _arg1 ")" >> in >> let html_node =3D span ~a:[onclick (start y)] "some text" >>=20 >> (* Client side post-parsed code: *) >> let _ =3D register_closure some_unique_name (fun _arg1 -> f _arg1) >>=20 >>=20 >>=20 >> If the example isn't clear enough I can detail it a little bit more. >>=20 >>=20 >> 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. >>=20 >> 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. >=20 > 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. >=20 > What I suggest you is to directly use camlp4 filters, for instance by = changing > the meaning of some constructor application and labels for = antiquotations: >=20 > (* Pre-parsed code: *) > let start =3D On (f ~y) in > let html_node =3D > span ~a:[onclick start] "some text" (* a is used for (html) = attributes *) >=20 > Have fun, >=20 > --=20 > Nicolas Pouillard > http://nicolaspouillard.fr >=20 > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs