From: skaller <skaller@users.sourceforge.net>
To: Nicolas Pouillard <nicolas.pouillard@gmail.com>
Cc: "Harrison, John R" <john.r.harrison@intel.com>, caml-list@inria.fr
Subject: Re: [Caml-list] Hacking the lexer in the new camlp4
Date: Fri, 30 Mar 2007 03:07:58 +1000 [thread overview]
Message-ID: <1175188078.2454.32.camel@rosella.wigram> (raw)
In-Reply-To: <cd67f63a0703290829j73222254n49a05b1031919317@mail.gmail.com>
On Thu, 2007-03-29 at 17:29 +0200, Nicolas Pouillard wrote:
> On 3/29/07, Harrison, John R <john.r.harrison@intel.com> wrote:
> > | > In the current camlp4, the only way I found to do this was basically
> > | > to copy the existing lexer and edit it. Although it works, it's ugly
> > | > and invariably means that I've had to change something with almost
> > | > every new version of camlp4. Does the new camlp4 offer a nicer way
> > of
> > | > changing the lexer?
> > |
> > | How did you that in the previous one without copy/paste the old lexer?
> Ok, so the new one is build with ocamllex, so it's not really extensible.
This doesn't follow entirely. There are at least two ways to
extend ocamllex lexers.
1. Recursively process a given lexeme.
2. Dispatch the error case with enough information to start
another lexer.
Method 1 can either tokenise the given lexeme, or simply
use it as a trigger to start another lexer. Method 2 is
just a special case of method 1.
All you really need is to pass the lexer a class with
an overridable method for each lexemical class the lexer
recognizes, which accepts the state data, and returns
a list of tokens.
Ocamllex currently ensures that the state of the buffer
is ready to process the next character after the lexeme
just decoded, even if it had to overshoot to get
there.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
prev parent reply other threads:[~2007-03-29 17:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-28 22:22 Harrison, John R
2007-03-29 9:30 ` [Caml-list] " Nicolas Pouillard
2007-03-29 15:11 ` Harrison, John R
2007-03-29 15:29 ` Nicolas Pouillard
2007-03-29 17:07 ` 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=1175188078.2454.32.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=john.r.harrison@intel.com \
--cc=nicolas.pouillard@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