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 B1E4FBC69 for ; Fri, 30 Mar 2007 18:13:59 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.224]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2UGDwTa003372 for ; Fri, 30 Mar 2007 18:13:59 +0200 Received: by nz-out-0506.google.com with SMTP id r28so455213nza for ; Fri, 30 Mar 2007 09:13:57 -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=SmDBZ+nXhodKZzmL96XJtLw63ZEf2cjV6MUyO24TuZNSbb3wEXW/4QRqpBEx0Zwilmr2W5UvbCpR6N6OqbTdDZKwvkcX37cDJz7Qbzz5a1Ww5OEFappMEuSYVQ9AkL/70gkCjZDbnlfV9NwJxiN4rQvUX04gaSH5ioC2h1xNNks= 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=nJ9DdUzpUnNgQ9BKO0kf++53/pXNK+WkGsz+NqOg3qH8w6LFHvOhfFtNZOpW8CalHkq2QCAZ9Ab1aikzYsU5o8L/Q/zL9fL1iRlImpBsffeD+Ks95zN2xRX/VK4Iy2YWfzrbxzCoRF8RzEyn3U0X46sr//8BfklVXs74u2qa530= Received: by 10.114.122.2 with SMTP id u2mr802992wac.1175271237560; Fri, 30 Mar 2007 09:13:57 -0700 (PDT) Received: by 10.114.183.4 with HTTP; Fri, 30 Mar 2007 09:13:57 -0700 (PDT) Message-ID: Date: Fri, 30 Mar 2007 18:13:57 +0200 From: "Nicolas Pouillard" To: "Hendrik Tews" Subject: Re: [Caml-list] camlp4 3.10 questions Cc: caml-list@yquem.inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <17930.60913.933794.204656@tandem.cs.ru.nl> X-j-chkmail-Score: MSGID : 460D3746.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 460D3746.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 hendrik:01 tews:01 tews:01 hendrik:01 sig:01 camlp:01 expr:01 expr:01 nop:01 interf:01 flattening:01 syntax:01 parser:01 syntax:01 On 3/30/07, Hendrik Tews wrote: > "Nicolas Pouillard" writes: > > On 3/29/07, Hendrik Tews wrote: > > "Nicolas Pouillard" writes: > > > > > 2. There are various maps and folds on asts in Sig.Camlp4Ast. How > > > can I use them? > > > > 2/ There is a lot of shortcuts to made the use of them easier when one > > just want to hook up only one thing (expressions for instance). > > > > The same example. > > > > open Camlp4.PreCast > > let f = Ast.map_expr begin function > > | <:expr< $x$ + 0 >> | <:expr< 0 + $x$ >> -> x > > | e -> e > > end in > > AstFilters.register_str_item f#str_item > > > > That should be AstFilters.register_str_item f ? > > Nop, giving the up to date signature of Ast.map_exp: > > value map_expr : (expr -> expr) -> map; > > Where does this come from? I only found > > value map_expr : (expr -> expr) -> expr -> expr; Yes that's the old one. > > > 8. How can I process multiple files with the same camlp4 process? > > You're right only one file (implem or interf). > So you can't by command line. > > Well, I guessed that. But how about using the API? I've put an example in camlp4/example/parse_files.ml I've also improved a little the API by flattening the small modules Syntax.{Parser,Printer,Warning} into Syntax itself. The example make a new syntax module (the Caml one), then parse two files make, then join both ASTs, and then print it. (*******************************) open Camlp4.PreCast;; module CamlGram = MakeGram(Lexer);; module Caml = Camlp4.Printers.OCaml.Make (Camlp4OCamlParser.Make (Camlp4OCamlRevisedParser.Make (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation))));; let parse f = let ic = open_in f in let strm = Stream.of_channel ic in let res = Caml.parse_implem (Loc.mk f) strm in close_in ic; res;; let ghost = Loc.ghost;; let main () = let a = parse "apply_operator_test.ml" in let b = parse "global_handler_test.ml" in Caml.print_implem <:str_item@ghost< module Apply_operator_test = struct $a$ end;; module Global_handler_test = struct $b$ end >> ;; try main () with e -> Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e; exit 1;; (*******************************) Best regards, -- Nicolas Pouillard