From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 6769CBBAF for ; Wed, 25 Jun 2008 14:17:40 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqgCAJLUYUjAXQImiGdsb2JhbACLN4ceAQEBDyCfEg X-IronPort-AV: E=Sophos;i="4.27,702,1204498800"; d="asc'?scan'208";a="14509458" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 25 Jun 2008 14:16:52 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m5PCGpMS027452 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 25 Jun 2008 14:16:52 +0200 X-IronPort-AV: E=Sophos;i="4.27,702,1204498800"; d="asc'?scan'208";a="12516423" Received: from peray.inria.fr (HELO ausone.inria.fr) ([128.93.8.98]) by mail2-relais-roc.national.inria.fr with SMTP; 25 Jun 2008 14:16:51 +0200 Received: by ausone.inria.fr (sSMTP sendmail emulation); Wed, _d Jun 2008 14:16:26 +0200 From: "Nicolas Pouillard" Cc: caml-list Subject: Re: [Caml-list] Custom lexer in Camlp4 To: Jeremy Yallop References: <4860F097.1000701@ed.ac.uk> <1214317779-sup-8964@port-ext16.ensta.fr> <486104FF.1080201@ed.ac.uk> <1214321827-sup-3937@port-ext16.ensta.fr> <4862319E.506@ed.ac.uk> In-Reply-To: <4862319E.506@ed.ac.uk> Date: Wed, 25 Jun 2008 14:16:22 +0200 Message-Id: <1214396011-sup-1262@port-ext16.ensta.fr> User-Agent: Sup/git Content-Type: multipart/signed; protocol="application/pgp-signature"; boundary="=-1214396186-724367-3412-5830-2-="; micalg="pgp-sha1" MIME-Version: 1.0 X-Miltered: at discorde with ID 48623733.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lexer:01 camlp:01 lexer:01 camlp:01 ocaml:01 grammars:01 functor:01 struct:01 expander:01 expander:01 syntax:01 doable:01 persuade:98 lexical:01 lexical:01 X-Attachments: cset="UTF-8" type="application/pgp-signature" name="signature.asc" name="signature.asc" --=-1214396186-724367-3412-5830-2-= Content-Type: text/plain; charset=UTF-8 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 --=-1214396186-724367-3412-5830-2-= Content-Disposition: attachment; filename="signature.asc" Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkhiNxYACgkQj+FCNw9dwLkXcgCgndwLq4Q1BqDTWAvdElrTs9AC sSgAn2C5bx77GxpzwG3t0chdDU5r4uka =TZYE -----END PGP SIGNATURE----- --=-1214396186-724367-3412-5830-2-=--