caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Custom lexer in Camlp4
Date: Wed, 25 Jun 2008 14:16:22 +0200	[thread overview]
Message-ID: <1214396011-sup-1262@port-ext16.ensta.fr> (raw)
In-Reply-To: <4862319E.506@ed.ac.uk>

[-- Attachment #1: Type: text/plain, Size: 1831 bytes --]

Excerpts from Jeremy Yallop's message of Wed Jun 25 13:53:02 +0200 2008:
> Nicolas Pouillard wrote:
> > Excerpts from Jeremy Yallop's message of Tue Jun 24 16:30:23 +0200 2008:
> >> Nicolas Pouillard wrote:
> >>> Excerpts from Jeremy Yallop's message of Tue Jun 24 15:03:19 +0200 2008:
> >>>> Is there a way to replace the default lexer in Camlp4?  I'd like to use 
> >>>> (an extended version of) one of the OCaml grammars, but with a different 
> >>>> lexer.
> >>> You can rebuild (I mean functor application), your own camlp4 by giving
> >>> another Lexer module. Basically you will have to copy/paste the short
> >>> Camlp4.PreCast module (or a part of), by substituting Camlp4.Struct.Lexer
> >>> by your Lexer implementation. That's fairly heavy but works.
> >> Ok, I've built a slightly modified clone of PreCast.  What's the best 
> >> way to persuade Camlp4 to use it?  The original PreCast seems fairly 
> >> hardwired, e.g. in the Register module.
> > 
> > Hum, you can't you have to build your own camlp4 driver :(
> 
> Thanks, Nicolas.  That's useful to know.
> 
> The solution I've adopted for now is to change the default quotation 
> expander to a function that just slots in my lexer before calling the 
> original expander.  This means that I can use my custom lexical syntax 
> inside the << >> delimiters and I can use those delimiters either around 
> the whole program or around a particular term.  I think this'll be fine 
> for my needs, although it would be nice to be able to customize the 
> lexer that's used for regular code as well.

You've  followed  a  reasonable  approach,  where one use quotations to embed a
"foreign"  language  in  the  sense that it even doesn't share the same lexical
conventions.

However your right that changing the lexer should be doable.

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

  reply	other threads:[~2008-06-25 12:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-24 13:03 Jeremy Yallop
2008-06-24 14:32 ` [Caml-list] " Nicolas Pouillard
2008-06-24 14:30   ` Jeremy Yallop
2008-06-24 15:16     ` Richard Jones
2008-06-24 15:43       ` Hezekiah M. Carty
2008-06-24 15:54         ` Nicolas Pouillard
2008-06-24 16:04         ` Hezekiah M. Carty
2008-06-24 16:59       ` Yaron Minsky
2008-06-25  8:41         ` Richard Jones
2008-06-25  9:17           ` Christophe TROESTLER
2008-06-24 15:37     ` Nicolas Pouillard
2008-06-24 15:43       ` Andrej Bauer
2008-06-25 11:53       ` Jeremy Yallop
2008-06-25 12:16         ` Nicolas Pouillard [this message]
2008-06-24 16:07 ` Pietro Abate

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=1214396011-sup-1262@port-ext16.ensta.fr \
    --to=nicolas.pouillard@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=jeremy.yallop@ed.ac.uk \
    /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).