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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 2A43DBBAF for ; Mon, 26 Jul 2010 18:05:26 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUCAM5OTUxKfVIukGdsb2JhbACfWAgVAQEBAQkJDAcRAx+0XYVdiQIBAQMFhTEEhAiEXIdh X-IronPort-AV: E=Sophos;i="4.55,262,1278280800"; d="scan'208";a="54762092" Received: from mail-ww0-f46.google.com ([74.125.82.46]) by mail3-smtp-sop.national.inria.fr with ESMTP; 26 Jul 2010 18:05:25 +0200 Received: by wwb18 with SMTP id 18so332521wwb.3 for ; Mon, 26 Jul 2010 09:05:25 -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:content-transfer-encoding; bh=LgyhQkldEQ7iYkqxcz7A2kuQ8KqOcaR4D3CSqW2Hou0=; b=RmI6uU+oXwb5jfyw7kYnnaoTJC/IUhFvOus6KKF2z227ljeOs+V/U4ZeG1mU/RPezX 5hVbfca3T+7OO3KQt5Rl+BVMQyTk18ElF1ElEweAaQrZ3RHa4ssPbmnvRBPJx5DSH14h NKnPsx6GPDX6t94lBcTDFwoLKXslFS7PkHyVE= 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 :content-transfer-encoding; b=Ys/57Jvl0lRconWdkMx/DCgan7BPNwwi5lTdASph0d4FUf/oRTblEMDI6HvOV+lpXH l2IoYJhrRYGvG/XlOOP+7f/EPICnqNeMpqGBhraNgjoSxV86D18wQIujpR39S985jpkn vxyZCdIE3odb6xy3csPIgCnXDqYf8+7qbylPU= Received: by 10.216.177.81 with SMTP id c59mr3194301wem.8.1280160325175; Mon, 26 Jul 2010 09:05:25 -0700 (PDT) MIME-Version: 1.0 Sender: jake.donham@gmail.com Received: by 10.216.186.17 with HTTP; Mon, 26 Jul 2010 09:05:04 -0700 (PDT) In-Reply-To: <9828C252-847B-4921-902D-376412CD7F16@gmail.com> References: <4c4da611.e8e9d80a.53b5.5b50@mx.google.com> <9828C252-847B-4921-902D-376412CD7F16@gmail.com> From: Jake Donham Date: Mon, 26 Jul 2010 09:05:04 -0700 X-Google-Sender-Auth: 75uYRQKpo5W2Rqaalx27mEVIQRI Message-ID: Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax To: Joel Reymont Cc: Nicolas Pouillard , "caml-list@yquem.inria.fr" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; camlp:01 expander:01 ocaml:01 syntax:01 ocaml:01 syntax:01 camlp:01 parser:01 parser:01 expr:01 foo:01 foo:01 parses:01 26,:98 quot:98 On Mon, Jul 26, 2010 at 8:41 AM, Joel Reymont wrote: > What if the quotation is not valid OCaml syntax, e.g. C#, and a Camlp4 pa= rser for it exists? > > How would I tie it all together to parse the quotation, plug in =A0antiqu= otations and end up with the custom AST that my parser outputs? There is an example of this in the jslib library in ocamljs: http://github.com/jaked/ocamljs/tree/master/src/jslib/ and a somewhat simpler one for JSON here: http://github.com/jaked/cufp-metaprogramming-tutorial/tree/master/ocaml/j= son_quot/ I hope to post a full explanation of this shortly. The magic is the Camlp4MetaGenerator filter, which generates functions to "lift" your custom AST into the OCaml AST, either as an expr or a patt. So e.g. your custom constructor Foo becomes ExId (_, IdUid (_, "Foo")) (respectively PaId). When you write <:lang< foo >> (where "foo" parses to Foo) in an expression, you get Foo in the expanded OCaml AST. Jake