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 <nicolas.pouill...@gmail.com> 
wrote:

> On Mon, 26 Jul 2010 16:41:46 +0200, Raphael Proust <raphla...@gmail.com> 
> 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
> 
> _______________________________________________
> 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

_______________________________________________
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

Reply via email to