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.5 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id E2D90BBC4 for ; Tue, 31 Mar 2009 04:14:13 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqUAAM8Y0UlCbwQckWdsb2JhbACWAgEBAQEJCwoHEQS0E4N6Bg X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="26672067" Received: from out4.smtp.messagingengine.com ([66.111.4.28]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Mar 2009 04:14:13 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id DAE3330B831; Mon, 30 Mar 2009 22:14:11 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Mon, 30 Mar 2009 22:14:11 -0400 X-Sasl-enc: 8maW+N3cRpy5a4XvYCh/7MOFHTgLAJ3ec4L1vNjUYE0S 1238465651 Received: from [192.168.1.10] (ALyon-157-1-87-173.w90-37.abo.wanadoo.fr [90.37.198.173]) by mail.messagingengine.com (Postfix) with ESMTPSA id 3343C4EEB2; Mon, 30 Mar 2009 22:14:11 -0400 (EDT) Message-ID: <49D17BAF.1060702@ens-lyon.org> Date: Tue, 31 Mar 2009 04:10:55 +0200 From: Martin Jambon User-Agent: Thunderbird 2.0.0.17 (X11/20081008) MIME-Version: 1.0 To: Florent.Ouchet@imag.fr Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] integer regular expressions References: <20090330192129.32152seaqvtmfb15@webmail.imag.fr> In-Reply-To: <20090330192129.32152seaqvtmfb15@webmail.imag.fr> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 syntax:01 semantics:01 pointers:01 ocaml:01 syntax:01 wrote:01 integer:01 integer:01 caml-list:01 int:01 int:01 jambon:01 jambon:01 arbitrary:02 Florent.Ouchet@imag.fr wrote: > Hello, > > I'm looking for a way to match integer numbers (immediate values), whose > types may be either int, int32, int64 or big_int. A conversion to string > in order to use string (perl compatible) regular expressions is likely > not the solution I'm looking for because it will not allow integer > specific matches. > > For instance (not normative), the regular expression syntax and > semantics would allow complex matches such as "0%30" === "this integer > matches if and only if its modulo to 30 is equal to 0". As in string > regular expressions, operator | will implement a logical or... > > I googled a little but all the results are always related to string > regular expressions :( any pointers? any existing Caml code? You want something called "views" or "active patterns". You can do that in OCaml with mikmatch, which includes such syntax extension. See http://martin.jambon.free.fr/mikmatch-manual.html#htoc10 Here is your example: let view Mod30 = fun x -> x mod 30 = 0 (* but not: let view Mod m = fun x -> x mod m = 0 but it could be implemented without difficulty (if really needed). *) let test x = match x with %Mod30 -> ... | ... -> Of course the whole point is to use %Mod30 within arbitrary patterns, otherwise it wouldn't be useful. I you want to match regular expressions over anything else than bytes, there's nothing out-of-the-box. You can define views on lists that would consume any number of elements, but it is pretty limited. Martin -- http://mjambon.com/