Browse thread
[Caml-list] ANNOUNCE: mod_caml 1.0.6 - includes security patch
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2004-01-16 (18:03) |
From: | Brian Hurt <bhurt@s...> |
Subject: | Re: [Caml-list] ANNOUNCE: mod_caml 1.0.6 - includes security patch |
On Fri, 16 Jan 2004, Richard Jones wrote: > Being able to write: > > var ~ /ab+/ > > and similar certainly makes string handling and simple parsing a lot > easier. > That (or something close to that) could be done via a library. What I'd like to see is to be able to pattern match on regexs, like: match str with | /ab+/ -> ... | /foo(bar)*/ -> ... etc. The compiler could then combine all the matchings into a single DFA, improving performance over code like: if (regex_match str "ab+") then ... else if (regex_match str "foo(bar)*") then ... else ... The regex matching would also let the compiler know if there were possible unmatched strings (these would should up as transitions to the error state in the DFA). Hmm. Actually, you could get close to this. You simply write a function with the signature: val multiway_regex: (string * 'a) list -> string -> 'a The assumption here is that 'a would be a variant type. This would allow you to do: type my_regex_matching = Abb | Foobar | ... ;; let regex = multiway_regex [ ("ab+", Abb); ("foo(bar)*", Foobar); ... ];; match (regex string) with | Abb -> (* matched /ab+/ *) | FooBar -> (* matched /foo(bar)*/ *) ... No- you'd want to be able to grab the substrings. So the type should be: val multiway_regex: (string * (string list -> 'a)) list -> string -> 'a Where the string list passed in to the generator function would be the list of substrings matched inside parens. -- "Usenet is like a herd of performing elephants with diarrhea -- massive, difficult to redirect, awe-inspiring, entertaining, and a source of mind-boggling amounts of excrement when you least expect it." - Gene Spafford Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners