From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pA5LJCls015126 for ; Sat, 5 Nov 2011 22:19:12 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvYBAPSntU7RVdK2mGdsb2JhbABDhCtPo3KBGAgiAQEBAQEICQ0HFCWBcgEBAQEDDAYCDx0BGx4DDAYDAgsNAgImAgIiAREBBQEcBgESIp9iCosNR4Jjg3U9iHACBQqBJoZlgRYElCGNPz2DcQ X-IronPort-AV: E=Sophos;i="4.69,462,1315173600"; d="scan'208";a="128643460" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Nov 2011 22:19:07 +0100 Received: by iabz21 with SMTP id z21so7192718iab.27 for ; Sat, 05 Nov 2011 14:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=ebtFb8oPJ8ISHF+2jjPT7USAzaTN1fCQasIrhs1+ZUg=; b=kXVimLt0UA1PYlgTDkxVtZ/0MRuLMBLk11MgusfpDp9vEYkTxERwwi0cZ28pEHgvJK EKgcd6cI/hENQryJtUSTFVoNIiByXTYSZ7WRj7omOcHfefDBtABOFeEa4/ALBIJNkUhl g66j8QKlmaw5wjAr5PTkDiN2oS/pl10TXjYsw= MIME-Version: 1.0 Received: by 10.231.48.203 with SMTP id s11mr751315ibf.90.1320527945847; Sat, 05 Nov 2011 14:19:05 -0700 (PDT) Received: by 10.142.81.17 with HTTP; Sat, 5 Nov 2011 14:19:05 -0700 (PDT) In-Reply-To: <20111103091646.GA24501@solaria.dimino.org> References: <20111103091646.GA24501@solaria.dimino.org> Date: Sat, 5 Nov 2011 22:19:05 +0100 Message-ID: From: Nicolas Pouillard To: Jun Furuse , caml-list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id pA5LJCls015126 Subject: Re: [Caml-list] Is it possible to extend OCaml lexer rules via Camlp4? On Thu, Nov 3, 2011 at 10:16 AM, Jérémie Dimino wrote: > Hi, > > On Thu, Nov 03, 2011 at 04:12:29PM +0900, Jun Furuse wrote: >> I want to have pcre regexp literals in the same syntax as Perl i.e. >> /hello\sworld\\n/. Currently what we do in OCaml is Pcre.regexp >> "hello\\sworld\\\\n", where the backslash char must be escaped in a >> OCaml string literal. This is lousy for scripting in OCaml. As said earlier Camlp4's lexer is not extensible. One can change the meaning of the token stream using the token filters but this won't work in your case. The third option is to use quotations this is really the adapted feature for this task. Of course the syntax won't be as concise as /bla/... Regarding OCaml lexing you may be interested in camllexer [1] which is not intended to be extensible but is very small and selfcontained. If you really want to hack your own lexical syntax I suggest you to fork camllexer and change it for your purpose. [1]: https://github.com/np/camllexer Best regards, -- Nicolas Pouillard http://nicolaspouillard.fr