From d228557c3c400ba7a81ba0b0fd867ec78bb35015 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 10 Apr 2012 03:11:09 -0700 Subject: * eval.c (eval_init): Expose regex-compile and regexp as intrinsics. * lib.c (obj_init): Change spelling of nongreedy operator and put it into the user package so that it is available for use with regex-compile. * regex.c (match_regex, search_regex): Bugfix: optional start position argument argument not defaulting to zero. * txr.1: Documented regex-compile and regexp. * txr.vim: Highlighting regex-compile and regexp. --- ChangeLog | 15 +++++++++++++++ eval.c | 3 +++ lib.c | 2 +- regex.c | 5 +++++ txr.1 | 40 ++++++++++++++++++++++++++++++++++++++++ txr.vim | 2 +- 6 files changed, 65 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78e14054..77694b90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2012-04-10 Kaz Kylheku + + * eval.c (eval_init): Expose regex-compile and regexp as intrinsics. + + * lib.c (obj_init): Change spelling of nongreedy operator and put + it into the user package so that it is available for use with + regex-compile. + + * regex.c (match_regex, search_regex): Bugfix: optional start + position argument argument not defaulting to zero. + + * txr.1: Documented regex-compile and regexp. + + * txr.vim: Highlighting regex-compile and regexp. + 2012-04-09 Kaz Kylheku Port to NetBSD (5.1). diff --git a/eval.c b/eval.c index c683a0b3..960ca4be 100644 --- a/eval.c +++ b/eval.c @@ -2221,10 +2221,13 @@ void eval_init(void) reg_fun(intern(lit("max"), user_package), func_n1v(maxv)); reg_fun(intern(lit("min"), user_package), func_n1v(minv)); + reg_fun(intern(lit("regex-compile"), user_package), func_n1(regex_compile)); + reg_fun(intern(lit("regexp"), user_package), func_n1(regexp)); reg_fun(intern(lit("search-regex"), user_package), func_n4o(search_regex, 2)); reg_fun(intern(lit("match-regex"), user_package), func_n3o(match_regex, 2)); reg_fun(intern(lit("regsub"), user_package), func_n3(regsub)); + reg_fun(intern(lit("make-hash"), user_package), func_n3(make_hash)); reg_fun(intern(lit("hash"), user_package), func_n0v(hashv)); reg_fun(intern(lit("hash-construct"), user_package), func_n2(hash_construct)); diff --git a/lib.c b/lib.c index 3b116464..f858df16 100644 --- a/lib.c +++ b/lib.c @@ -4115,7 +4115,7 @@ static void obj_init(void) var_s = intern(lit("var"), system_package); expr_s = intern(lit("expr"), system_package); regex_s = intern(lit("regex"), system_package); - nongreedy_s = intern(lit("nongreedy"), system_package); + nongreedy_s = intern(lit("ng0+"), user_package); compiled_regex_s = intern(lit("compiled-regex"), system_package); quote_s = intern(lit("quote"), system_package); qquote_s = intern(lit("qquote"), system_package); diff --git a/regex.c b/regex.c index 2fc08c64..eddb3b0e 100644 --- a/regex.c +++ b/regex.c @@ -1644,6 +1644,9 @@ static regm_result_t regex_machine_feed(regex_machine_t *regm, wchar_t ch) val search_regex(val haystack, val needle_regex, val start, val from_end) { + if (!start) + start = zero; + if (length_str_lt(haystack, start)) { return nil; } else { @@ -1698,6 +1701,8 @@ val match_regex(val str, val reg, val pos) regex_machine_t regm; val i, retval; regm_result_t last_res = REGM_INCOMPLETE; + if (!pos) + pos = zero; regex_machine_init(®m, reg); diff --git a/txr.1 b/txr.1 index 6fb80aa2..1507eada 100644 --- a/txr.1 +++ b/txr.1 @@ -7274,6 +7274,46 @@ Examples: ;; Replace Hello with Goodbye: (regsub #/Hello/ "Goodbye" "Hello world!") -> "Goodbye world!" +.SS Function regexp + +.TP +Syntax: + + (regexp ) + +.TP +Description: + +The regexp function returns t if is a compiled regular expression +object. For any other object type, it returns nil. + +.SS Function regex-compile + +.TP +Syntax: + + (regex-compile
) + +.TP +Description: + +The regex compile function takes the source code of a regular expression, +expressed as a Lisp data structure, and compiles it to a regular expression +object. + +.TP +Examples: + + ;; the equivalent of #/[a-zA-Z0-9_/ + (regex-compile '(set (#\ea . #\ez) (#\eA . #\eZ) (#\e0 . #\e9) #\e_)) + + ;; the equivalent of #/.*/ and #/.+/ + (regex-compile '(0+ wild)) + (regex-compile '(1+ wild)) + + ;; #/a|b|c/ + (regex-compile '(or (or #\ea #\eb) #\ec)) + .SS Functions make-hash, hash .SS Function sethash diff --git a/txr.vim b/txr.vim index dff02491..67cde861 100644 --- a/txr.vim +++ b/txr.vim @@ -48,7 +48,7 @@ syn keyword txl_keyword contained floor ceil sin cos tan asin acos atan log exp syn keyword txl_keyword contained fixnump bignump integerp floatp syn keyword txl_keyword contained numberp zerop evenp oddp > syn keyword txl_keyword contained zerop evenp oddp > < >= <= = max min -syn keyword txl_keyword contained search-regex match-regex regsub +syn keyword txl_keyword contained search-regex match-regex regsub regexp regex-compile syn keyword txl_keyword contained make-hash hash hash-construct gethash sethash pushhash remhash syn keyword txl_keyword contained hash-count get-hash-userdata set-hash-userdata hashp maphash syn keyword txl_keyword contained hash-eql hash-equal -- cgit v1.2.3