From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 8E3DABC69 for ; Sat, 24 Feb 2007 03:52:34 +0100 (CET) Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1O2qXuk001271 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 24 Feb 2007 03:52:34 +0100 Received: from [80.229.56.224] (helo=beast.local) by pih-relay04.plus.net with esmtp (Exim) id 1HKn1T-0006lj-I9 for caml-list@yquem.inria.fr; Sat, 24 Feb 2007 02:52:31 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Case-insensitive lexing Date: Sat, 24 Feb 2007 02:46:13 +0000 User-Agent: KMail/1.9.5 References: <23E977DC-77FF-44A2-8675-5EAA8F61505F@gmail.com> In-Reply-To: <23E977DC-77FF-44A2-8675-5EAA8F61505F@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200702240246.13960.jon@ffconsultancy.com> X-Miltered: at discorde with ID 45DFA872.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lexing:01 lexer:01 ocamllex:01 preprocess:01 ocamllex:01 lexing:01 buf:01 buf:01 lowercase:01 lexbuf:01 ocaml:01 ocaml:01 frog:98 char:01 wrote:01 On Friday 23 February 2007 15:32, Joel Reymont wrote: > Is there a way to make a case-insensitive lexer with ocamllex? Preprocess the character stream, making all chars lower case before they even reach ocamllex. Take the existing definition of Lexing.from_channel: let from_channel ic = from_function (fun buf n -> input ic buf 0 n) and alter it to change the case of chars as they are read (off the top of my head): let from_case_insensitive_channel ic = let aux buf n = let i = input ic buf 0 n in for i=0 to i-1 do buf.[i] <- Char.lowercase buf.[i] done; i in from_function aux Now create your lexbuf using from_case_insensitive_channel. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists