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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id E26F4BC6B for ; Wed, 7 Nov 2007 16:29:00 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIpoMUfAXQImh2dsb2JhbACBW40hAQEBCAopgQ8 X-IronPort-AV: E=Sophos;i="4.21,385,1188770400"; d="scan'208";a="4155072" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 07 Nov 2007 16:29:00 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lA7FT098011387 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 7 Nov 2007 16:29:00 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE9oMUeCulhph2dsb2JhbACBW40hAQEBCAQGKYEP X-IronPort-AV: E=Sophos;i="4.21,385,1188770400"; d="scan'208";a="3994581" Received: from fiton.bononia.it ([130.186.88.105]) by mail2-smtp-roc.national.inria.fr with ESMTP; 07 Nov 2007 16:28:59 +0100 Received: from aquarium.takhisis.invalid (fiton.bononia.it [130.186.88.105]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Stefano Zacchiroli", Issuer "sockmel.bononia.it" (verified OK)) by fiton.bononia.it (Postfix) with ESMTP id 4407338038 for ; Wed, 7 Nov 2007 16:28:41 +0100 (CET) Received: by aquarium.takhisis.invalid (Postfix, from userid 1000) id 997801240F6; Wed, 7 Nov 2007 16:28:48 +0100 (CET) Date: Wed, 7 Nov 2007 16:28:48 +0100 From: Stefano Zacchiroli To: Inria Ocaml Mailing List Subject: Re: [Caml-list] [camlp4] how to parse/pretty print OCaml source files Message-ID: <20071107152848.GA19628@takhisis.invalid> Mail-Followup-To: Inria Ocaml Mailing List References: <20071106181431.GA19764@takhisis.invalid> <1194375800-sup-2076@ausone.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1194375800-sup-2076@ausone.local> User-Agent: Mutt/1.5.17 (2007-11-01) X-Miltered: at discorde with ID 4731D9BC.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; zacchiroli:01 zack:01 camlp:01 ocaml:01 0100,:01 camlp:01 pcaml:01 syntax:01 sig:01 parser:01 occurences:01 syntax:01 mli:01 toplevel:01 strm:01 On Tue, Nov 06, 2007 at 08:09:28PM +0100, Nicolas Pouillard wrote: > > - what's the corresponding camlp4 idiom for the old "Pcaml.parse_implem" > > (which used to parse str_items starting from a "char Stream.t")? > > [ Note that I need to parse the revised syntax, but I doubt this will > > make a sensible difference. ] First things first :), so let's start with parsing ... > Looking for parse_implem in Camlp4/Sig.ml that some module have the signature > Parser(Ast).S, searching for occurences of this signature leads me to two > signatures Syntax and Camlp4Syntax. Then I go to Camlp4/PreCast.mli where all > precasted modules lives. Here I found that Camlp4.PreCast.Syntax have the > Camlp4Syntax type. > > So Camlp4.PreCast.Syntax.parse_implem is what you searched. OK. > However you perhaps need a function more precise that reading an implementation. You perhaps prefer just reading a toplevel phrase for this you can use: > > open Camlp4.PreCast;; > > let strm = ... in > Syntax.Gram.parse loc Syntax.top_phrase strm That's right, parsing one phrase at a time is definitely handier. However the above does not work. (The argument are permuted, but that of course is a non issue.) What does "loc" stands for? Given I'm parsing a char stream I would have expected that the parser returns me a located object, why should I give a location in advance? Is it some kind of "current" location when parsing has been left last time? In this case how should I build a location? The only way I've found is Camlp4.PreCast.Loc.mk which takes as input a file name and returns a location placed at the beginning of that file. I'm going for Loc.ml "", but I don't know if I'll mess up something in the future ... TIA, Cheers. -- Stefano Zacchiroli -*- PhD in Computer Science ............... now what? zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/ (15:56:48) Zack: e la demo dema ? /\ All one has to do is hit the (15:57:15) Bac: no, la demo scema \/ right keys at the right time