Browse thread
Case-insensitive lexing
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] Case-insensitive lexing |
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