summaryrefslogtreecommitdiff
path: root/src/regex.urs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2015-08-26 20:35:02 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2015-08-26 20:35:02 -0400
commit7e59cdc766d922b72f74f6c8625d7c9cdafa4752 (patch)
tree11c13991ff21a36cc343c6694b30b77c9dc5595d /src/regex.urs
parent676bae0d916ca88fe2de61a749b237d03997503d (diff)
Add functions which operate on strings instead of counted slices
Diffstat (limited to 'src/regex.urs')
-rw-r--r--src/regex.urs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/regex.urs b/src/regex.urs
index 6e7bdcc..d3b0815 100644
--- a/src/regex.urs
+++ b/src/regex.urs
@@ -16,8 +16,8 @@ specific language governing permissions and limitations under the License. *)
This library implements ECMAScript regular expressions. *)
-type substring = {Start : int, Len : int}
-type match = {Whole : substring, Groups : list substring}
+type match a = {Whole : a, Groups : list a}
+type counted_substring = {Start : int, Len : int}
(* Searching *)
@@ -25,12 +25,14 @@ type match = {Whole : substring, Groups : list substring}
'Some match' if a match succeeds and 'None' otherwise. *)
val match : string (* needle *)
-> string (* haystack *)
- -> option match
+ -> option (match string)
+val match' : string -> string -> option (match counted_substring)
(* Finds _all_ matches for a regular expression in a string. *)
val all_matches : string (* needle *)
-> string (* haystack *)
- -> list match
+ -> list (match string)
+val all_matches' : string -> string -> list (match counted_substring)
(* Replacement *)
@@ -44,9 +46,13 @@ val replace : string (* needle *)
(* Transforms a string by applying a function to replace every match in the
string. *)
val transform_matches : string (* needle *)
- -> (match -> string) (* transformation *)
+ -> (match string -> string) (* transformation *)
-> string (* haystack *)
-> string
+val transform_matches' : string
+ -> (match counted_substring -> string)
+ -> string
+ -> string
(* Executes a general regex-guided transformation over a string. Matches
'needle' against any part of 'haystack', splitting 'haystack' into matching and
@@ -74,7 +80,12 @@ evaluates to
"_a_*x*_b_*x*__"
*)
val transform : string (* needle *)
- -> (substring -> string) (* non-matching transformation *)
- -> (match -> string) (* matching transformation *)
+ -> (string -> string) (* non-matching transformation *)
+ -> (match string -> string) (* matching transformation *)
-> string (* haystack *)
-> string
+val transform' : string
+ -> (counted_substring -> string)
+ -> (match counted_substring -> string)
+ -> string
+ -> string