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 85B75BBAF for ; Mon, 26 Jul 2010 16:41:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUCAJY7TUxKfVK0kGdsb2JhbACDFJxICBUBAQEBCQkMBxEDH7E5O4IQhTwuiFQBAQMFhD5zBIhk X-IronPort-AV: E=Sophos;i="4.55,261,1278280800"; d="scan'208";a="66947775" Received: from mail-wy0-f180.google.com ([74.125.82.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 26 Jul 2010 16:41:47 +0200 Received: by wyb33 with SMTP id 33so2621105wyb.39 for ; Mon, 26 Jul 2010 07:41:46 -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:content-type; bh=xyR9/iXHfuMDmvRBZ9KRoLtPT4mgSdsJ0y0cP9Zds9w=; b=bxNDE4qGsyK5NeIAbvrHjTHEOOzuL1yYDaLXuOJYXRTKhPLYuPyjtrN7IdPpVBC03Y y9PXYuwZ/Bpypo1q+jskmAH4RzJbrjM8JxiCDjoY/Yk70WuGgX4nBUF3ff2aRmOIlFvM iogq9wMUFwH3ILE02L+8bRuYwzrxee+V4YIVI= 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 :content-type; b=mHHxAT+jYxP8xlXnys7nps6RHzhr+0/Wv3zNs8qgzCKvYe5q4hLzm53SR6CUmEVPTe /Eedkks6yD8ISCdt/EBa5rK35mnFOGVYNXe4w2+T7nJyUW9l+qojcdP4dreIfFktZ4qA Lw/kktqraNl1i1qHBXmAKTdhYzkiE6O0G1K2U= MIME-Version: 1.0 Received: by 10.227.133.18 with SMTP id d18mr3165870wbt.33.1280155306551; Mon, 26 Jul 2010 07:41:46 -0700 (PDT) Received: by 10.216.182.132 with HTTP; Mon, 26 Jul 2010 07:41:46 -0700 (PDT) In-Reply-To: References: Date: Mon, 26 Jul 2010 16:41:46 +0200 Message-ID: Subject: [Camlp4] Quotation expander with OCaml syntax From: Raphael Proust To: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=001485f78c0a4deaef048c4b6249 X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 syntax:01 runtime:01 abstracted:01 node:01 node:01 camlp:01 ocaml:01 expander:01 parser:01 parser:01 expr:01 X-Attachments: cset="UTF-8" cset="UTF-8" --001485f78c0a4deaef048c4b6249 Content-Type: text/plain; charset=UTF-8 Hi all, 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. I considered an alternative solution: treating quotations as raw text (with a custom quotation expander) but that would destroy any _loc information and make compile time warnings and errors quite difficult to locate. Is there a simpler/fitter way of doing that? (Is the Y correct wrt the X?) How can one embed the original parser in a quotation expander? (I couldn't find a function of type string -> Ast.expr in the Camlp4 doc/mlis, but I'd be happy to be pointed to one if it exists. I think it would at least require some functor application.) Does anyone know of any example that resemble what I'm trying to achieve? -- _______ Raphael --001485f78c0a4deaef048c4b6249 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all,

I'm= working on a syntax extension as part of an internship in the
Ocsigen team. The aim o= f the syntax extension is to split the code of a web
application in two separate files: one for the client and one fo= r the server. A
few transformations are= to take place in the process.

Quotations are to be transformed i= nto client code while antiquotations can refer
to server side values t= ransmitted to the client at runtime.


In order to avoid any XY p= roblems, here is an abstracted and simplified example
of the expected behavio= r:

(* Pre-parsed code: *)
let start =3D <:on&l= t; f $y$ >> in
let html_node =3D

=C2=A0span ~a:[onclick = start] "some text" (* a is used for (html) attributes *)
(* Server side post-par= sed code: *)
let start _arg1 =3D =C2=A0"call_closur= e(some_unique_name," ^ mymarshall _arg1 ")"
in
let html_node =3D span = ~a:[onclick (start y)] "some text"

(* Client side post-pa= rsed code: *)
let _ =3D register_clos= ure some_unique_name (fun _arg1 -> f _arg1)



If the example isn't clear enough I can deta= il it a little bit more.


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 quotat= ion 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.

I consi= dered an alternative solution: treating quotations as raw text (with a
custom quotation expand= er) but that would destroy any _loc information and make
compile time warnings and errors quite difficult to locate.<= /span>



How can one embed the original parser in a quota= tion expander? (I couldn't find
a function of type stri= ng -> Ast.expr in the Camlp4 doc/mlis, but I'd be happy
to be pointed to one if it exists. I think it would at= least require some
functor application.)

Does anyone know of any example that resemble what I'm trying to= achieve?



= --
_______
Raphael

--001485f78c0a4deaef048c4b6249--