From bc6b0bee8fe4120642029daaa8ce6c069ef667b8 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Wed, 26 Aug 2015 17:29:32 -0400 Subject: Rework replacement API to rely on transformation Redesign library API around highly general regex-based transformations. Instead of specifying a string to substitute for each match, you now execute an entire function over the match (and over nonmatching regions as well). The resulting C++ code is much simpler, with more functionality pushed into Ur, and the engine now supports certain types of regex transformations needed to mimic Perl. --- src/regex__FFI.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/regex__FFI.h') diff --git a/src/regex__FFI.h b/src/regex__FFI.h index 84b81a9..7399005 100644 --- a/src/regex__FFI.h +++ b/src/regex__FFI.h @@ -26,27 +26,28 @@ extern "C" { #include typedef struct { - char* haystack; - void* result; -} uw_Regex__FFI_match; + long start; + long length; +} uw_Regex__FFI_substring_t; -uw_Basis_bool uw_Regex__FFI_succeeded(struct uw_context*, - const uw_Regex__FFI_match); +typedef void* uw_Regex__FFI_substring_list_t; -uw_Basis_int uw_Regex__FFI_n_subexpression_matches(struct uw_context*, - const uw_Regex__FFI_match); +uw_Basis_int uw_Regex__FFI_substring_start(struct uw_context*, + const uw_Regex__FFI_substring_t); -uw_Basis_string uw_Regex__FFI_subexpression_match(struct uw_context*, - const uw_Regex__FFI_match, - const uw_Basis_int); +uw_Basis_int uw_Regex__FFI_substring_length(struct uw_context*, + const uw_Regex__FFI_substring_t); -uw_Regex__FFI_match uw_Regex__FFI_do_match(struct uw_context*, - const uw_Basis_string, - const uw_Basis_string); +uw_Basis_int uw_Regex__FFI_substring_list_length( + struct uw_context*, const uw_Regex__FFI_substring_list_t); -uw_Basis_string uw_Regex__FFI_replace(struct uw_context*, const uw_Basis_string, - const uw_Basis_string, - const uw_Basis_string); +uw_Regex__FFI_substring_t uw_Regex__FFI_substring_list_get( + struct uw_context*, const uw_Regex__FFI_substring_list_t, + const uw_Basis_int); + +uw_Regex__FFI_substring_list_t uw_Regex__FFI_do_match(struct uw_context*, + const uw_Basis_string, + const uw_Basis_string); #ifdef __cplusplus } -- cgit v1.2.3