From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D98A1BC6B for ; Mon, 9 Jul 2007 15:06:49 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.229]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l69D6mWm019903 for ; Mon, 9 Jul 2007 15:06:49 +0200 Received: by nz-out-0506.google.com with SMTP id x7so561557nzc for ; Mon, 09 Jul 2007 06:06:48 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fRxAUdZ34Q1Xh7XA0cyvM427mrBFnX1YhO2kcMFS0lyuZk8EmQmyKdD3A8qFy6tvSaVNk2GkpxhWa84WyfwJZ4buyowHhNqedkjYr8J1+m8YnQ3KhlC7LEyC7SoYpvDv+a2Sr2iejgNwd4vPTN/ZlBnekXcvw70G0JMxIa+qDjY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=mRsdBz1wur6DQCfYHxCAssx5Et/jMDhzAEJK3Yg5RT9XWYhOtzqcQlWnp5tteo0SUu0bWFarZ3WhOs0gT8cJUxWr2opkN2suB/jgeAU/1cEPNLJFgmSr1x3y4JzyZGIiVRAuF60ODzrfGKqTIScDmBRczew1uqXz7fK4o4R3EhU= Received: by 10.114.132.5 with SMTP id f5mr3076823wad.1183986407486; Mon, 09 Jul 2007 06:06:47 -0700 (PDT) Received: by 10.114.181.8 with HTTP; Mon, 9 Jul 2007 06:06:47 -0700 (PDT) Message-ID: Date: Mon, 9 Jul 2007 15:06:47 +0200 From: "Nicolas Pouillard" To: "Jon Harrop" Subject: Re: [Caml-list] try .. finally using new camlp4 Cc: caml-list@yquem.inria.fr In-Reply-To: <200707080114.42213.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200707080114.42213.jon@ffconsultancy.com> X-j-chkmail-Score: MSGID : 469232E8.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 469232E8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 camlp:01 syntax:01 afaict:01 functor:01 expr:01 expr:01 syntax:01 sig:01 struct:01 ocaml:01 parsers:01 annotations:01 parsers:01 val:01 On 7/8/07, Jon Harrop wrote: > > I'm just getting my toe wet with the new camlp4 and I can't get this simple > syntax extension to work. AFAICT, the following code: > Let's go > > open Camlp4.PreCast;; Useless since you use the functor based approach. > let expr : Camlp4.PreCast.Ast.expr Camlp4.PreCast.Gram.Entry.t = > Gram.Entry.mk "expression" Useless too why make a new (empty) rule, there is already one that one wants to extend. > module Example (Syntax : Camlp4.Sig.Camlp4Syntax) = struct > open Camlp4.PreCast Useless too > include Syntax > > let printer = > let module P = Camlp4.Printers.OCaml.Make(Syntax) in > new P.printer () Useless too > EXTEND Gram > expr: LEVEL "top" > [[ "try"; f=expr; "finally"; g=expr -> Here one extend a rule. So in order to have something working properly one *must* look at the original rule. There is the up-to-date rule: $ cvs ann -r release310 camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml | grep '"try"' Annotations for camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml *************** 1.2.2.11 (pouillar 04-Apr-07): | "try"; e = sequence; "with"; a = match_case -> So the correct rule is: [[ "try"; f=sequence; "finally"; g=expr -> > <:expr< > ((function > | `Val v, g -> g(); v > | `Exn e, g -> g(); raise e) > ((try `Val($f$) with e -> `Exn e), (fun () -> $g$))) > >>]]; > END > end > > module M = Camlp4.Register.OCamlSyntaxExtension(Id)(Example) The Id module is missing... So there is the fixed code: module Id = struct let name = "pa_tryfinally" let version = "$Id:$" end module Example (Syntax : Camlp4.Sig.Camlp4Syntax) = struct include Syntax EXTEND Gram expr: LEVEL "top" [[ "try"; f=sequence; "finally"; g=expr -> <:expr< ((function | `Val v, g -> g(); v | `Exn e, g -> g(); raise e) ((try `Val($f$) with e -> `Exn e), (fun () -> $g$))) >>]]; END end module M = Camlp4.Register.OCamlSyntaxExtension(Id)(Example) > > should provide the syntax extension. Compile with: > > $ ocamlc -dtypes -pp camlp4of -I /usr/lib/ocaml/3.10.0/camlp4 -linkall > camlp4lib.cma unix.cma Camlp4Parsers/Camlp4OCamlRevisedParser.cmo > Camlp4Parsers/Camlp4OCamlParser.cmo Camlp4Printers/Camlp4AutoPrinter.cmo > Camlp4Bin.cmo pa_tryfinally.ml -o pa_tryfinally Why link, with "-c" it's a lot simpler. ocamlc -c -dtypes -pp camlp4of -I +camlp4 pa_tryfinally.ml Cheers, -- Nicolas Pouillard