diff options
-rw-r--r-- | regex.c | 28 | ||||
-rw-r--r-- | regex.h | 4 | ||||
-rw-r--r-- | txr.1 | 77 |
3 files changed, 109 insertions, 0 deletions
@@ -2928,6 +2928,30 @@ val regex_range_all(val regex, val arg1, val arg2, val arg3) } } +val regex_range_full_fun(val regex, val pos) +{ + return curry_123_3(func_n3(regex_range_full), + regex, default_arg(pos, zero)); +} + +val regex_range_left_fun(val regex, val pos) +{ + return curry_123_3(func_n3(regex_range_left), + regex, default_arg(pos, zero)); +} + +val regex_range_right_fun(val regex, val end) +{ + if (null_or_missing_p(end)) + return curry_123_2(func_n3(regex_range_right), regex, end); + return curry_123_3(func_n3(regex_range_left), regex, end); +} + +val regex_range_search_fun(val regex, val start, val from_end) +{ + return curry_1234_1(func_n4(range_regex), regex, start, from_end); +} + val read_until_match(val regex, val stream_in, val include_match_in) { regex_machine_t regm; @@ -3116,6 +3140,10 @@ void regex_init(void) reg_fun(intern(lit("r$"), user_package), func_n3o(regex_range_right, 2)); reg_fun(intern(lit("rr"), user_package), func_n4o(regex_range_search, 2)); reg_fun(intern(lit("rra"), user_package), func_n4o(regex_range_all, 2)); + reg_fun(intern(lit("fr^$"), user_package), func_n2o(regex_range_full_fun, 1)); + reg_fun(intern(lit("fr^"), user_package), func_n2o(regex_range_left_fun, 1)); + reg_fun(intern(lit("fr$"), user_package), func_n2o(regex_range_right_fun, 1)); + reg_fun(intern(lit("frr"), user_package), func_n3o(regex_range_search_fun, 1)); init_special_char_sets(); } @@ -55,6 +55,10 @@ val regex_range_left(val regex, val arg1, val arg2); val regex_range_right(val regex, val arg1, val arg2); val regex_range_search(val regex, val arg1, val arg2, val arg3); val regex_range_all(val regex, val arg1, val arg2, val arg3); +val regex_range_full_fun(val regex, val pos); +val regex_range_left_fun(val regex, val pos); +val regex_range_right_fun(val regex, val end); +val regex_range_search_fun(val regex, val start, val from_end); int wide_display_char_p(wchar_t ch); void regex_init(void); void regex_free_all(void); @@ -34623,6 +34623,83 @@ and --> nil .cble +.coNP Functions @, fr^$ @, fr^ @ fr$ and @ frr +.synb +.mets (fr^$ < regex <> [ position ]) +.mets (fr^ < regex <> [ position ]) +.mets (fr$ < regex <> [ end-position ]) +.mets (frr < regex <> [[ start-position ] << from-end ]) +.syne +.desc +These regular expression functions do not directly +perform regex operations. Rather, they each return +a function of one argument which performs a regex +operation. + +The returned functions perform the same operations as, +respectively, +.codn r^$ , +.codn r^ , +.code r$ +and +.codn rr . + +The following equivalences nearly hold, except that some of the +functions on the right side produced by op +.code op +can accept additional arguments after the input string, +whereas the functions on the left produced by +.code f^$ +.I "et al." +accept only one parameter: the input string. + +.cblk + [fr^$ r] <--> (op m^$ r) + [fr^$ r p] <--> (op m^$ r p) + [fr^ r] <--> (op m^ r) + [fr^ r p] <--> (op m^ r p) + [fr$ r] <--> (op m$ r) + [fr$ r p] <--> (op m$ r p) + [frr r] <--> (op m$ r) + [frr r s] <--> (op m$ r s) + [frr r s fe] <--> (op m$ r s fe) +.cble + +That is to say, +.code fr^$ +returns a function which binds +.meta regex +and possibly the optional +.metn position . +When this function is invoked, it must be given an argument +which is a string. It performs the same operation as +.code r^$ +being called on +.meta regex +and possibly +.metn position , +and the string. +The same holds between +.code fr^ +and +.codn r^ , +between +.code fr$ +and +.codn r$ , +and between +.code frr +and +.codn rr . + +.TP* Examples: + +.cblk + ;; Remove leading digits from "123A456", other than first digit: + (regsub (fr^ #/\ed+/ 1) "" "123A456") + --> "1A456" +.cble + .SS* Hashing Library .coNP Functions @ make-hash and @ hash .synb |