From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: skaller@users.sourceforge.net
Cc: Radu Grigore <radugrigore@gmail.com>,
"yjc01@doc.ic.ac.uk" <yjc01@doc.ic.ac.uk>,
caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] index of substring
Date: Fri, 28 Jan 2005 09:51:58 +0100 [thread overview]
Message-ID: <16889.64814.187592.903001@gargle.gargle.HOWL> (raw)
In-Reply-To: <1106844935.12114.62.camel@pelican.wigram>
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)
next prev parent reply other threads:[~2005-01-28 8:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-27 0:41 yjc01
2005-01-27 4:21 ` [Caml-list] " Matt Gushee
2005-01-27 6:44 ` Radu Grigore
2005-01-27 9:36 ` skaller
2005-01-27 10:20 ` Jean-Christophe Filliatre
2005-01-27 16:55 ` skaller
2005-01-27 17:20 ` Radu Grigore
2005-01-28 8:51 ` Jean-Christophe Filliatre [this message]
2005-01-28 13:31 ` skaller
2005-01-27 8:37 ` Oliver Bandel
2005-01-27 9:17 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16889.64814.187592.903001@gargle.gargle.HOWL \
--to=jean-christophe.filliatre@lri.fr \
--cc=caml-list@inria.fr \
--cc=radugrigore@gmail.com \
--cc=skaller@users.sourceforge.net \
--cc=yjc01@doc.ic.ac.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).