From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA11812; Wed, 30 Oct 2002 20:23:02 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA12206 for ; Wed, 30 Oct 2002 20:23:01 +0100 (MET) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9UJN0500368 for ; Wed, 30 Oct 2002 20:23:00 +0100 (MET) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id UAA02921 for caml-list@inria.fr; Wed, 30 Oct 2002 20:23:00 +0100 Date: Wed, 30 Oct 2002 20:23:00 +0100 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] camlp4: How to hook into the char stream of an existing grammar? Message-ID: <20021030202300.A2893@verdot.inria.fr> References: <15808.9712.523008.590596@gargle.gargle.HOWL> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <15808.9712.523008.590596@gargle.gargle.HOWL>; from tews@tcs.inf.tu-dresden.de on Wed, Oct 30, 2002 at 07:33:20PM +0100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Wed, Oct 30, 2002 at 07:33:20PM +0100, Hendrik Tews wrote: > > I have the following question: Suppose I use camlp4 with a > predefined grammar (such as pa_o.cmo). Is it possible to install > a function that intercept the character stream that flows into > the lexer of camlp4 (for instance to record the positions of > newlines)? You can patch the function which is called to parse implementations, which is Pcaml.parse_implem. It is a reference which is defined by default as: Grammar.Entry.parse Pcaml.implem. Try the below file "foo.ml" as syntax extension: ocamlc -c -I +camlp4 foo.ml This command prints the positions of newlines in file bar.ml: camlp4o ./foo.cmo pr_null.cmo bar.ml ------------------------------------------ (* file foo.ml *) let f cs = let mycs = Stream.from (fun i -> try let c = Stream.next cs in if c = '\n' then begin Printf.eprintf "newline at pos %d\n" i; flush stderr; end; Some c with Stream.Failure -> None) in Grammar.Entry.parse Pcaml.implem mycs ;; let _ = Pcaml.parse_implem := f ------------------------------------------ -- Daniel de RAUGLAUDRE http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners