From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id F1FF4BB91 for ; Fri, 28 Jan 2005 14:31:26 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0SDVQxe024736 for ; Fri, 28 Jan 2005 14:31:26 +0100 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 OAA04679 for ; Fri, 28 Jan 2005 14:31:25 +0100 (MET) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0SDVNZ6009375 for ; Fri, 28 Jan 2005 14:31:25 +0100 Received: from [192.168.1.200] (ppp205-248.lns1.syd3.internode.on.net [203.122.205.248]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id j0SDV9dY076766; Sat, 29 Jan 2005 00:01:10 +1030 (CST) Subject: Re: [Caml-list] index of substring From: skaller Reply-To: skaller@users.sourceforge.net To: Jean-Christophe Filliatre Cc: Radu Grigore , "yjc01@doc.ic.ac.uk" , caml-list In-Reply-To: <16889.64814.187592.903001@gargle.gargle.HOWL> References: <1106786478.41f838aecb7dd@www.doc.ic.ac.uk> <7f8e92aa05012622441fce509b@mail.gmail.com> <1106818582.6734.154.camel@pelican.wigram> <16888.49247.996632.225091@gargle.gargle.HOWL> <1106844935.12114.62.camel@pelican.wigram> <16889.64814.187592.903001@gargle.gargle.HOWL> Content-Type: text/plain Message-Id: <1106919068.23562.74.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 29 Jan 2005 00:31:09 +1100 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41FA3EAE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41FA3EAB.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 sourceforge:01 filliatre:01 wrote:01 ocamllex:01 ocamllex:01 lexbuf:01 lexing:01 mutable:01 ocaml:01 inverted:01 lexeme:01 lexbuf:01 lexer:01 ocaml:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: On Fri, 2005-01-28 at 19:51, Jean-Christophe Filliatre wrote: > But that's precisely why ocamllex is so a powerful tool. You only need > to know that ocamllex is building a set of mutually recusvive > functions with the lexbuf as argument and then you are not limited in > what you can do in the actions. You can even pass additional arguments > to the lexing functions. Yes, this is all true, provided you think of your code as a stream pattern matcher: unfortunately lexbufs are mutable rather than functional (which I suppose is necessary for performance). > I like to think about ocamllex as a general-purpose tool to insert a > bit of regular expressions in ocaml programs Yes, although the code is control inverted initially, that is, your client action code is *called* with a lexeme and lexbuf (and callbacks are a bit nasty sometimes). Of course you also call the lexer to fetch what the callback returns .. so yes I guess you can see this as 'inserting' a bit of regular expressions into an ocaml program. Interesting tradeoffs here! Ocaml lexers allow input iterators (eg file streams) by using a lexbuf, but aren't functional because the lexbuf modified. Felix uses a C++ style forward iterator, and is purely functional -- the end of lexeme pointer is returned to be used in the next call as the new starting point -- but if you want to handle an input iterator you have to manage the buffering yourself. [Ahem .. which can't be done transparently at the moment .. woops .. design fault!] -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net