Browse thread
index of substring
-
yjc01@d...
- Matt Gushee
-
Radu Grigore
-
skaller
-
Jean-Christophe Filliatre
-
skaller
- Radu Grigore
- Jean-Christophe Filliatre
-
skaller
-
Jean-Christophe Filliatre
-
skaller
- Oliver Bandel
- Xavier Leroy
[
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: | Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...> |
| Subject: | Re: [Caml-list] index of substring |
skaller writes:
> On Thu, 2005-01-27 at 21:20, Jean-Christophe Filliatre wrote:
> >
> > What's wrong with this way of handling nested comments with ocamllex:
> >
> > ======================================================================
> >
> > | "(*" { comment lexbuf; ... }
> > ...
> >
> > and comment = parse
> > | "(*" { comment lexbuf; comment lexbuf }
> > | "*)" { () }
> > | _ { comment lexbuf }
> >
>
> Well it doesn't handle (* or *) in strings ..
I was only focusing on nested comments, but handling strings is rather
trivial. See the ocaml lexer for instance (where you can see that
introducing a new lexing function "string" is definitely better than
trying to write a regular expression for strings literals).
> However, whilst this code (given a fix
> to handle strings) would probably work,
> it isn't a plain lexer, but a mix of lexing
> and client code.
Sure, it is clearly more powerful than an automaton (since nested
comments are not regular), if this is what you mean by "isn't a plain
lexer".
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.
I like to think about ocamllex as a general-purpose tool to insert a
bit of regular expressions in ocaml programs (lexers, but also
filters, file formats readers, line counters, code indenters, etc.)
and not only as a tool to write lexers. With the header and trailer,
it is even easy to build a whole ocaml program within a single
ocamllex file. For instance, two programs of mine I use intensively
are a program to count lines of code and comment in my ocaml programs
(a 173 lines long ocamllex file) and a preprocessor for my web pages
(a 129 lines long ocamllex file).
--
Jean-Christophe Filliātre (http://www.lri.fr/~filliatr)