Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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?

Cheers,

Till