From: Berke Durak <berke.durak@exalead.com>
To: Till Varoquaux <till.varoquaux@gmail.com>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Ocamllex newline counting...
Date: Fri, 07 Mar 2008 16:39:45 +0100 [thread overview]
Message-ID: <47D161C1.2050401@exalead.com> (raw)
In-Reply-To: <9d3ec8300803070157y6bb173eew865e2f232cb4c789@mail.gmail.com>
Till Varoquaux a écrit :
> 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?
Well, as you said, wrapping using Lexing.from_function to count newlines
or whatever you want is "just fine" in most cases; especially given that
you'll often want to build a byte-offset-to-line-number table while parsing.
Putting specialized logic in lexing doesn't seem very elegant...
My wild guess would be that the lexer_position record probably got those
extra lnum fields because they were needed in the compiler and they didn't
want to change the interface to insert a type parameter for the positions.
Am I right?
--
Berke DURAK
next prev parent reply other threads:[~2008-03-07 15:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-07 9:57 Till Varoquaux
2008-03-07 15:39 ` Berke Durak [this message]
2008-03-12 1:00 ` [Caml-list] " Nathaniel Gray
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=47D161C1.2050401@exalead.com \
--to=berke.durak@exalead.com \
--cc=caml-list@inria.fr \
--cc=till.varoquaux@gmail.com \
/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