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.0 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 3678CBBAF for ; Wed, 25 Jun 2008 13:53:13 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlMAAIHOYUhTkhUHmmdsb2JhbACBW5EXAQEBAQEIBQgHEQOfEw X-IronPort-AV: E=Sophos;i="4.27,702,1204498800"; d="scan'208";a="12515472" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 25 Jun 2008 13:53:07 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m5PBr6Sd027917 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 25 Jun 2008 13:53:06 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlMAAIHOYUhTkhUHmmdsb2JhbACBW5EXAQEBAQEIBQgHEQOfEw X-IronPort-AV: E=Sophos;i="4.27,702,1204498800"; d="scan'208";a="12515470" Received: from smtp.dslgb.com (HELO cht-smtp-001.bulldogdsl.com) ([83.146.21.7]) by mail2-smtp-roc.national.inria.fr with ESMTP; 25 Jun 2008 13:53:06 +0200 Received: by cht-smtp-001.bulldogdsl.com (Postfix, from userid 1011) id BFE2A4E58EC; Wed, 25 Jun 2008 12:53:05 +0100 (BST) Received: from [192.168.123.191] (host-84-9-233-41.dslgb.com [84.9.233.41]) by cht-smtp-001.bulldogdsl.com (Postfix) with ESMTP id 0B0E34E5855; Wed, 25 Jun 2008 12:53:03 +0100 (BST) Message-ID: <4862319E.506@ed.ac.uk> Date: Wed, 25 Jun 2008 12:53:02 +0100 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.14 (X11/20080509) MIME-Version: 1.0 To: Nicolas Pouillard Cc: caml-list Subject: Re: [Caml-list] Custom lexer in Camlp4 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> In-Reply-To: <1214321827-sup-3937@port-ext16.ensta.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 486231A2.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 persuade:98 lexical:01 wrote:01 wrote:01 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. Jeremy