caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Damien Doligez <damien.doligez@inria.fr>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Lexing.lexeme_start_p broken?
Date: 21 Sep 2004 19:25:02 +1000	[thread overview]
Message-ID: <1095758700.2580.857.camel@pelican.wigram> (raw)
In-Reply-To: <F4E39A08-0BA7-11D9-A295-00039310CAE8@inria.fr>

On Tue, 2004-09-21 at 18:26, Damien Doligez wrote:
> On Sep 20, 2004, at 16:44, skaller wrote:

> The token supplying function is supposed to _update_ the lexbuf, if
> you want the parser to report the correct locations.  ocamllex does
> some of the work by updating the char count, 

Not in my case it doesn't. 
The lexing function isn't an ocamllex lexer.
So I'd have to update the char count too.

I actually am using ocamllex, but I drive it manually
to collect a token list, then feed the list to the parser.

Hmmm.. OK, how is this for an idea:

Suppose we add to the lexbuf a mutable field of type:

	lexbuf -> loc

which returns the location information the parser needs
given a lexbuf. The parser then fetches the location
information by calling this function on the lexbuf
from which it was obtained.

I can then provide a function which accepts my own
state object and curry it. This way, I don't have
to keep updating the lexbuf, and the parser cannot
see the lexbuf details. My routine might be
expensive -- but it only gets called once when
there is a parse error, not every token.

Whilst I don't think this is a perfect solution,
it does seem to partially decouple the parser from
the lexbuf by at least abstracting it using a function.

Would this interfere with the Ocaml bootstrap?

*** a better solution might be to pass this function
directly the the parser, thereby decoupling it
entirely from the lexer. However that changes the
type of parser functions. That can easily be fixed
though -- just make a compatibility wrapper which 
calls the full parser function, passing a default
function value.

If there was any interest, I could probably provide
a design which provided proper decoupling, whilst
retaining compatibility using wrappers and defaults.
[But I imagine it could also be done easily by someone
on the Ocaml team -- and throw in a user state object
at the same time please, as has been done for the lexer :]

The parser does need to get tokens, and it may need
location information, but it should not
depend on an object whose principle purpose is 
to support lexing.

In theory this is also true for generated lexers:
they shouldn't depend on any lexbufs. However for
performance reasons, abstracting a character source
probably isn't tolerable.


-- 
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



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2004-09-21  9:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-17 22:07 Scott Duckworth
2004-09-20  9:23 ` Jean-Christophe Filliatre
2004-09-20 14:44   ` skaller
2004-09-21  8:26     ` Damien Doligez
2004-09-21  9:25       ` skaller [this message]

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=1095758700.2580.857.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=damien.doligez@inria.fr \
    /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).