Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Camlp4] Quotation expander with OCaml syntax
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: bluestorm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax
On Mon, Jul 26, 2010 at 4:41 PM, Raphael Proust <raphlalou@gmail.com> wrote:
> 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.

Are you sure you need to split the code in two different files ? Could
you not produce only one file, emitting code for both the server and
the client behavior, with two separate entry point (say server_main()
and client_main()) to call from the outside ?

Pros :
- no need to split files (naming issues, location issues, etc.)
- easier to ensure consistency between the two sides (for example, if
you want type information to flow from one side to the other); might
be an important factor if you're doing non-trivial things

Cons :
- possibly less convenient to use
- client has to load the server code as well


> 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.

It seems to me that you would only handle antiquotations in
expressions (or do you have a "client-server communication" meaning
for antiquotations inside other syntaxic constructs such as types or
patterns ?). Matching some cases (in that case, one) in one of the
syntaxic classes is *very* easy and quite elegant thanks to the `map`
and `fold` classes of Camlp4Ast `foldmap` could also be helpful but it
seems it is not generated by default for Camlp4Ast. If you need it
(and I think you'd need it), you can simulate a mapfold by adding a
mutable state variable to a mapper class.