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 LAA13053; Mon, 20 Sep 2004 11:23:16 +0200 (MET DST) 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 LAA13024 for ; Mon, 20 Sep 2004 11:23:15 +0200 (MET DST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8K9NFim028804 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 20 Sep 2004 11:23:15 +0200 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id EDA8619E789; Mon, 20 Sep 2004 11:23:14 +0200 (CEST) Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 10564-07; Mon, 20 Sep 2004 11:23:14 +0200 (CEST) Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id DAA1C19E768; Mon, 20 Sep 2004 11:23:14 +0200 (CEST) Received: from pc8-142 (pc8-142 [129.175.8.142]) by smtp.lri.fr (Postfix) with ESMTP id BE693CEE11; Mon, 20 Sep 2004 11:23:13 +0200 (CEST) Received: from filliatr by pc8-142 with local (Exim 3.36 #1 (Debian)) id 1C9KOA-0005sw-00; Mon, 20 Sep 2004 11:23:14 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <16718.41346.210917.885719@gargle.gargle.HOWL> Date: Mon, 20 Sep 2004 11:23:14 +0200 To: Scott Duckworth Cc: caml-list@inria.fr Subject: Re: [Caml-list] Lexing.lexeme_start_p broken? In-Reply-To: <414B602F.2020400@clemson.edu> References: <414B602F.2020400@clemson.edu> X-Mailer: VM 7.18 under Emacs 21.3.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at concorde with ID 414EA183.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 filliatre:01 filliatre:01 lri:01 ocaml's:01 lnum:01 lnum:01 lri:01 filliatr:01 ocaml:01 ocaml:01 token:01 handles:01 writes:01 parser:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Scott Duckworth writes: > I can't seem to get the function Lexing.lexeme_start_p to return a > position with correct information in it. Here is my code (test.mll): In the Ocaml manual, in the documentation of the Lexing module, you can read: "Note that the lexing engine will only manage the pos_cnum field of lex_curr_p by updating it with the number of characters read since the start of the lexbuf. For the other fields to be accurate, they must be initialised before the first use of the lexbuf, and updated by the lexer actions." (below the "type lexbuf = ..."). To update these fields, the best way is to look into ocaml sources to see how this is done is ocaml's own parser. In file parsing/lexer.mll the function update_loc is doing the job, being called each time a newline character is read. It is quite complicated, because it handles many different things at the same time, but to update the fields pos_lnum and pos_bol, it can be simplified to let update_loc lexbuf = let pos = lexbuf.lex_curr_p in lexbuf.lex_curr_p <- { pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum } then you call this function for each newline in your lexer actions, e.g. | '\n' { newline lexbuf; token lexbuf } Hope this helps, -- Jean-Christophe Filliātre (http://www.lri.fr/~filliatr) ------------------- 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