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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 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 99492BBCA for ; Tue, 6 May 2008 18:36:26 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkYCAJMlIEjAXQImiGdsb2JhbACRfAEBAQ8gmiU X-IronPort-AV: E=Sophos;i="4.27,444,1204498800"; d="scan'208";a="10444225" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 May 2008 18:36:26 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m46GaPR4005210 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 6 May 2008 18:36:26 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgQBAJMlIEhCbwQZk2dsb2JhbACRfAEBAQEJAwgJEQOaIg X-IronPort-AV: E=Sophos;i="4.27,444,1204498800"; d="scan'208";a="11910751" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 May 2008 18:36:25 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 2DC92105728; Tue, 6 May 2008 12:36:24 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Tue, 06 May 2008 12:36:24 -0400 X-Sasl-enc: 2ZpBx3LFuMdKNqDYUUPmHSBbj1cfK2N3OZxEKnBEh59L 1210091783 Received: from [192.168.1.10] (ALyon-157-1-49-148.w83-201.abo.wanadoo.fr [83.201.200.148]) by mail.messagingengine.com (Postfix) with ESMTPSA id CDB7BBC4B; Tue, 6 May 2008 12:36:22 -0400 (EDT) Date: Tue, 6 May 2008 18:34:14 +0200 (CEST) From: Martin Jambon X-X-Sender: martin@martin.ec.wink.com To: Loup Vaillant Cc: Nicolas Pouillard , caml-list Subject: Re: [Caml-list] Help for Camlp4: Pcaml.input_file for 3.10? In-Reply-To: <6f9f8f4a0805060910v68c19a5dv76f9abcc879f1fb6@mail.gmail.com> Message-ID: References: <6f9f8f4a0805060257qaeeab15x5c1851099e4650ab@mail.gmail.com> <1210069851-sup-8648@port-ext16.ensta.fr> <6f9f8f4a0805060910v68c19a5dv76f9abcc879f1fb6@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 48208909.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 camlp:01 pcaml:01 pcaml:01 ocaml:01 camlp:01 wiki:01 preprocessed:01 foo:01 mll:01 foo:01 mll:01 syntax:01 cmo:01 mlast:01 On Tue, 6 May 2008, Loup Vaillant wrote: > 2008/5/6 Nicolas Pouillard : >> Excerpts from Loup Vaillant's message of Tue May 06 11:57:41 +0200 2008: >> > >> > I would like to know if there is any equivalent >> > of Pcaml.input_file in Ocaml 3.10's Camlp4. >> > I tried to search the wiki, but with no luck so far. >> > [...] >> >> If I clearly remember this ugly global variable has been removed. > > OK, I got it, thank you for the fast response. > > Now, I can have the name of the preprocessed file with _loc. Not exactly: usually you'll get the location in the source file, because of #line directives. The file being processed may not be the source file. For instance: source file: foo.mll file being processed by camlp4: foo.ml (locations refer to foo.mll) > But How can I include a file in another? More generally, do we have a > substitute for it? I'd like to know too. This is the syntax extension I wrote for the old camlp4, and as far as I remember it was working more or less: (*pp camlp4o pa_extend.cmo q_MLast.cmo -loc loc *) (* Created by Martin Jambon, 2004 *) (* No copyright, no guarantee *) let parse_stream s = let f = !Pcaml.parse_implem in let rec loop () = match f s with l, true -> List.map fst l @ loop () | l, false -> List.map fst l in loop () let parse_file file = let ic = open_in file in let stream = Stream.of_channel ic in let current_file = !Pcaml.input_file in Pcaml.input_file := file; (* it doesn't work *) let l = parse_stream stream in close_in ic; Pcaml.input_file := current_file; l EXTEND Pcaml.str_item: [ [ "USE"; file = STRING -> let l = parse_file file in <:str_item< declare $list:l$ end >> ] ]; END Martin -- http://wink.com/profile/mjambon http://mjambon.com