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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 0CA2BBBAF for ; Mon, 26 Jul 2010 22:08:52 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjYCAP+HTUzRVdY0kGdsb2JhbACfWwgVAQEBAQkJDAcRAx+yOoIQhhAuiFQBAQMFhTEEiGSCR4Ua X-IronPort-AV: E=Sophos;i="4.55,263,1278280800"; d="scan'208";a="56154602" Received: from mail-bw0-f52.google.com ([209.85.214.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 26 Jul 2010 22:08:51 +0200 Received: by bwz14 with SMTP id 14so3564733bwz.39 for ; Mon, 26 Jul 2010 13:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=Z/9UZKEW/SlrJDhR9VAzTAlR8gWs+vdzYbbOALDgXu4=; b=Fr+WfPpgC0YP20Giw6/x+1z9FH94imMXzz9f/NJxb+iPhtw+ZEaA0mr93uolnevaO4 f81LzZ6d+CrdZvZzK/twSsMPoE03gJmD+6JQOYWqcTcjmQb0e+ysDpXAEKO7qJUvBg2X txR8FCOIkpJMGmCcKkoHkzOdAeoVOpY1bC54E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=qv5sqts1xNpFb8rhAC1or+QMolfO9Lk7fyp1+422tttOfmp3zAwlB/sR1Pr1pHUSa7 zC+zT6UbTF7KEISlmV/g99BeLR/3OUC89AaEJZPvUDdB+fwHpoM4tnkpf3iUdLCHbBoL bxRTScxSjt9bKISqzzrJHy1s0gN6TSw+M9qq8= Received: by 10.204.115.203 with SMTP id j11mr5795055bkq.147.1280174931223; Mon, 26 Jul 2010 13:08:51 -0700 (PDT) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.204.22.82 with HTTP; Mon, 26 Jul 2010 13:08:31 -0700 (PDT) In-Reply-To: References: From: bluestorm Date: Mon, 26 Jul 2010 22:08:31 +0200 X-Google-Sender-Auth: 0P5vqsKs4vTUAls4B_8IcgUygFQ Message-ID: Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax To: Raphael Proust Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 syntax:01 non-trivial:01 camlp:01 ocaml:01 expander:01 simulate:01 mutable:01 26,:98 wrote:01 naming:01 caml-list:01 On Mon, Jul 26, 2010 at 4:41 PM, Raphael Proust 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.