From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 3E228BB83 for ; Tue, 18 Jul 2006 11:28:16 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k6I9SFQT008593 for ; Tue, 18 Jul 2006 11:28:15 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA19637 for ; Tue, 18 Jul 2006 11:28:15 +0200 (MET DST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6I9SEiT005922 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 18 Jul 2006 11:28:14 +0200 Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id 7E1C320215A; Tue, 18 Jul 2006 11:28:14 +0200 (CEST) Received: from pc9-152.lri.fr (pc9-152 [129.175.9.152]) by smtp.lri.fr (Postfix) with ESMTP id 9E2B5CED98; Tue, 18 Jul 2006 11:28:13 +0200 (CEST) Received: from filliatr by pc9-152.lri.fr with local (Exim 4.60) (envelope-from ) id 1G2lsF-0006fK-8Q; Tue, 18 Jul 2006 11:28:15 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <17596.43439.212571.801556@pc9-152.lri.fr> Date: Tue, 18 Jul 2006 11:28:15 +0200 To: Stefano Zacchiroli Cc: caml-list@inria.fr Subject: Re: [Caml-list] ocamllex -- ungetting a character? In-Reply-To: <20060716081203.GA25792@aquarium.takhisis.invalid> References: <44B9B93F.4010309@cs.caltech.edu> <20060716081203.GA25792@aquarium.takhisis.invalid> X-Mailer: VM 7.19 under Emacs 21.4.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at concorde with ID 44BCA9AF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44BCA9AE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocamllex:01 filliatre:01 filliatr:01 lri:01 zacchiroli:01 mvanier:01 ocamllex:01 lexing:01 buffer:01 lexbuf:01 regexp:01 lexbuf:01 ocaml:01 regexp:01 lexing:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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 ====================================================================== | { lexbuf.lex_curr_pos <- lexbuf.lex_curr_pos - 1; } ====================================================================== 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)