Version franaise
Home About Download Resources Contact us
Browse thread
The Implicit Accumulator: a design pattern using optional arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments
On Wed, 2007-06-27 at 14:31 -0400, Brian Hurt wrote:

> Actually, what I'd like is a more powerful regular expression engine-
> one where I can give multiple different patterns with constant values,
> and create a single regular expression that if the first pattern is
> matched, the first constant value is matched, etc.  Something with a
> signature like:


> let re = compile [ ("foo", 1); ("bar", 2); ("baz", 3) ]
> ~default:(-1);;
> 
> let f str =
>     match re_match re str with
>     | 1 -> (* it's a foo *)
>     | 2 -> (* it's a bar *)
>     | 3 -> (* it's a baz *)
>     | -1 -> (* it didn't match *)
> ;;
> 
> In other words, something like ocamllex, except dynamic.

I think you can do this now? it's just messy: use

	"(foo)|(bar)|(baz)"

and check which group 1, 2 or 3 matches.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net