caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <filliatr@lri.fr>
To: Stefano Zacchiroli <zack@bononia.it>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] ocamllex -- ungetting a character?
Date: Tue, 18 Jul 2006 11:28:15 +0200	[thread overview]
Message-ID: <17596.43439.212571.801556@pc9-152.lri.fr> (raw)
In-Reply-To: <20060716081203.GA25792@aquarium.takhisis.invalid>


Stefano Zacchiroli writes:
 > On Sat, Jul 15, 2006 at 08:57:51PM -0700, mvanier wrote:
 > > I'm writing a simple program using ocamllex to do some text processing, and 
 > > one feature I would really like is to be able to put a matched character 
 > > back onto the front of the lexing buffer.  I can't figure out a way to do 
 > > this from the documentation (if it's possible, it's not in the manual).  
 > > Does anyone know of a way to do this?
 > 
 > I don't think it is possible with ocamllex. 

Well, there  is at least an  ugly way to  do that, which is  to modify
lexbuf.lex_curr_pos manually, as in

======================================================================
  | <your regexp>   { lexbuf.lex_curr_pos <- lexbuf.lex_curr_pos - 1;
	              <your action> }
======================================================================

I've already used this with success  (yes, I feel ashamed :-). I would
like a  member of  the ocaml  development team to  confirm it,  but it
seems  safe, as long  as you  do not  backtrack before  the characters
matched by the  left hand-side regexp. Indeed, the  lexing engine will
not modify the lexbuf once the action is triggered and before the next
call to the lexer.

Hope this helps,
-- 
Jean-Christophe Filliâtre (http://www.lri.fr/~filliatr)


      reply	other threads:[~2006-07-18  9:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-16  3:57 mvanier
2006-07-16  8:12 ` [Caml-list] " Stefano Zacchiroli
2006-07-18  9:28   ` Jean-Christophe Filliatre [this message]

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=17596.43439.212571.801556@pc9-152.lri.fr \
    --to=filliatr@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=zack@bononia.it \
    /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).