caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: Scott Duckworth <duckwos@clemson.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Lexing.lexeme_start_p broken?
Date: Mon, 20 Sep 2004 11:23:14 +0200	[thread overview]
Message-ID: <16718.41346.210917.885719@gargle.gargle.HOWL> (raw)
In-Reply-To: <414B602F.2020400@clemson.edu>


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


  reply	other threads:[~2004-09-20  9:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-17 22:07 Scott Duckworth
2004-09-20  9:23 ` Jean-Christophe Filliatre [this message]
2004-09-20 14:44   ` skaller
2004-09-21  8:26     ` Damien Doligez
2004-09-21  9:25       ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16718.41346.210917.885719@gargle.gargle.HOWL \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=duckwos@clemson.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).