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 124CFBC0A for ; Sun, 13 May 2007 22:28:30 +0200 (CEST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.244]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4DKSTQs016864 for ; Sun, 13 May 2007 22:28:29 +0200 Received: by an-out-0708.google.com with SMTP id c2so374396anc for ; Sun, 13 May 2007 13:28:29 -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=GwNRMspWIrhIzprGBVI+ZmxRthEaR3GEApaIN9Xf/ItO8jcyuvOfwGXgfZgzLXNJgYzgExlq6U1oZFJlhlxxXhpzCzyBVcJtcnOYdQTNejCAGTfn/tjGpdaqAWsOLdTG0YLZdeicEzABxjXFPYEBAjWrH6QP10f2l4s3ChV+/lw= 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=L7wdfJRkBGAjBU/IyTfD5nUFkpTJ79EdrOPfAUI1v4jGHDGUXN0+5JOLTS/YtoNatAMqgcfkQC2i0iBFlJJuKZ22L9K/vBPu4fnC5y7Tla5zH/bzjEWSrqlQQ/WOzVMPT2uuZuRLlsaXTfP55/bwCI6WxTrZswrSifkZp7VXtyc= Received: by 10.114.113.1 with SMTP id l1mr723315wac.1179088108391; Sun, 13 May 2007 13:28:28 -0700 (PDT) Received: by 10.114.183.4 with HTTP; Sun, 13 May 2007 13:28:28 -0700 (PDT) Message-ID: Date: Sun, 13 May 2007 22:28:28 +0200 From: "Nicolas Pouillard" To: "Isaac Freeman" Subject: Re: [Caml-list] camlp4 and streams Cc: caml-list@yquem.inria.fr In-Reply-To: <6ff764650705130858s7bbc2263sc3d99ed9e8a4760c@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6ff764650705130858s7bbc2263sc3d99ed9e8a4760c@mail.gmail.com> X-j-chkmail-Score: MSGID : 464774ED.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 464774ED.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 camlp:01 expr:01 expr:01 ocaml:01 ocamlc:01 -pp:01 cmo:01 mlast:01 cmo:01 uncaught:01 pcaml:01 expander:01 mlast:01 syntax:01 On 5/13/07, Isaac Freeman wrote: > Hello, > > I am having some problems using streams in my camlp4 extentions. The code: > > EXTEND > expr: LEVEL "expr1" > [[ "yield"; e1 = expr LEVEL "simple"; > "continue"; e2 = expr LEVEL "simple" -> > <:expr< [< $e1$; $e2$ >] >> ]]; > END;; > > produces the error: > > isaac@lappy:~/stuff/ocaml$ ocamlc -pp "camlp4o pa_extend.cmo > q_MLast.cmo" -I +camlp4 -c gen-syntax.ml > File "gen-syntax.ml", line 8, characters 18-20: > While expanding quotation "expr": > Parse error: illegal begin of expression > Uncaught exception: Pcaml.Qerror("expr", 1, _) > Preprocessor error > > However, when I change the stream into a list, it works fine, so I'm > sure there is just some technicality in using streams here that I'm > not accounting for properly. Any ideas? You are hitting a limitation of the old camlp4 implementation. The thing is that the quotation expander <:expr<...>> provided by q_MLast.cmo is somewhat limited to the revised syntax. BTW in revised streams syntax is: [: ... :] (instead of [< ... >]) and elements starts with a backquote instead of a single quote. Indeed the stream syntax is provided as a syntactic sugar over regular OCaml code using the Stream module from the standard library. However the new Camlp4 implementation provided in 3.10 lift that shortcoming by giving a full reflection system. So if you want to use the original syntax everywhere you can use camlp4of that provided quotation (<:expr<...>>, patt, ctyp...) in the original syntax including syntactic sugars. Here is a 3.10 valid extension: $ cat ext.ml open Camlp4.PreCast;; open Syntax;; EXTEND Gram expr: LEVEL "top" [[ "yield"; e1 = expr LEVEL "simple"; "continue"; e2 = expr LEVEL "simple" -> <:expr< [< $e1$; $e2$ >] >> ]]; END;; $ ocamlc -c -I +camlp4 -pp camlp4of ext.ml $ camlp4o ./ext.cmo -str 'yield e1 continue e2' Stream.lapp (fun _ -> e1) (Stream.slazy (fun _ -> e2)) Best regards, -- Nicolas Pouillard