English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
index of substring
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-28 (13:31)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] index of substring
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