caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Florent.Ouchet@imag.fr
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] integer regular expressions
Date: Tue, 31 Mar 2009 04:10:55 +0200	[thread overview]
Message-ID: <49D17BAF.1060702@ens-lyon.org> (raw)
In-Reply-To: <20090330192129.32152seaqvtmfb15@webmail.imag.fr>

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/


  reply	other threads:[~2009-03-31  2:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-30 17:21 Florent.Ouchet
2009-03-31  2:10 ` Martin Jambon [this message]
2009-03-31  9:11   ` [Caml-list] " Florent Ouchet

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=49D17BAF.1060702@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=Florent.Ouchet@imag.fr \
    --cc=caml-list@yquem.inria.fr \
    /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).