* ocamllex -- ungetting a character?
@ 2006-07-16 3:57 mvanier
2006-07-16 8:12 ` [Caml-list] " Stefano Zacchiroli
0 siblings, 1 reply; 3+ messages in thread
From: mvanier @ 2006-07-16 3:57 UTC (permalink / raw)
To: caml-list
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?
Thanks in advance,
Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] ocamllex -- ungetting a character?
2006-07-16 3:57 ocamllex -- ungetting a character? mvanier
@ 2006-07-16 8:12 ` Stefano Zacchiroli
2006-07-18 9:28 ` Jean-Christophe Filliatre
0 siblings, 1 reply; 3+ messages in thread
From: Stefano Zacchiroli @ 2006-07-16 8:12 UTC (permalink / raw)
To: caml-list
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. Using ulex however you can
put back all the characters corresponding to the last matched lexeme
with Ulexing.rollback.
Cheers.
--
Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. -!-
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] ocamllex -- ungetting a character?
2006-07-16 8:12 ` [Caml-list] " Stefano Zacchiroli
@ 2006-07-18 9:28 ` Jean-Christophe Filliatre
0 siblings, 0 replies; 3+ messages in thread
From: Jean-Christophe Filliatre @ 2006-07-18 9:28 UTC (permalink / raw)
To: Stefano Zacchiroli; +Cc: caml-list
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)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-07-18 9:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-16 3:57 ocamllex -- ungetting a character? mvanier
2006-07-16 8:12 ` [Caml-list] " Stefano Zacchiroli
2006-07-18 9:28 ` Jean-Christophe Filliatre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox