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
Ocamllex newline counting...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-03-07 (09:57)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Ocamllex newline counting...
The title is pretty self explanetory: Ocamllex is able to keep track
of positions automatically but it needs help with new lines ( you need
to register new lines with a function like:

 let newline lexbuf =
    let pos = lexbuf.lex_curr_p in
    lexbuf.lex_curr_p <-
      { pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum }
This tends to pollute the code and require you to add additional rules
and underlying machinery. I can see one easy workaround: pipe the
function you build your lexer from trough an additional function that
registers newlines. This seems a bit costly at run time but should be
just fine in most cases.

Is there any fundamental reason I am missing why newlines are not
handled natively in the generated automaton?