caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* integer regular expressions
@ 2009-03-30 17:21 Florent.Ouchet
  2009-03-31  2:10 ` [Caml-list] " Martin Jambon
  0 siblings, 1 reply; 3+ messages in thread
From: Florent.Ouchet @ 2009-03-30 17:21 UTC (permalink / raw)
  To: caml-list

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?

Thanks,

Florent Ouchet


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] integer regular expressions
  2009-03-30 17:21 integer regular expressions Florent.Ouchet
@ 2009-03-31  2:10 ` Martin Jambon
  2009-03-31  9:11   ` Florent Ouchet
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambon @ 2009-03-31  2:10 UTC (permalink / raw)
  To: Florent.Ouchet; +Cc: caml-list

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/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] integer regular expressions
  2009-03-31  2:10 ` [Caml-list] " Martin Jambon
@ 2009-03-31  9:11   ` Florent Ouchet
  0 siblings, 0 replies; 3+ messages in thread
From: Florent Ouchet @ 2009-03-31  9:11 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1342 bytes --]

Martin Jambon a écrit :
> 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.
>   

Hello Martin,

That's an elegant way for writing custom pattern matches in OCaml code 
but that is not exactly what I am looking for. Your proposal fits well 
for fixed pattern matches while I would like to make the regular 
expressions customizable via the application command line (ie at 
run-time). A module dedicated to integer matches (like RegExp is to 
string matches) would fit better.

Regards,

Florent
VSYML - VHDL Symbolic Simulator in OCaml: 
http://users-tima.imag.fr/vds/ouchet/vsyml.html


[-- Attachment #2: florent.ouchet.vcf --]
[-- Type: text/x-vcard, Size: 309 bytes --]

begin:vcard
fn:Florent Ouchet
n:Ouchet;Florent
org:;CIS/VDS
adr;quoted-printable:46, avenue F=C3=A9lix Viallet,;;TIMA Laboratory - T131;GRENOBLE Cedex;;38031;France
email;internet:florent.ouchet@imag.fr
title:PhD student
tel;work:0476574872
x-mozilla-html:FALSE
url:http://tima.imag.fr
version:2.1
end:vcard


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-31  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-30 17:21 integer regular expressions Florent.Ouchet
2009-03-31  2:10 ` [Caml-list] " Martin Jambon
2009-03-31  9:11   ` Florent Ouchet

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).