diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-04-10 03:11:09 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-04-10 03:11:09 -0700 |
commit | d228557c3c400ba7a81ba0b0fd867ec78bb35015 (patch) | |
tree | 0a5aaca7ead1d53d89a30fab76b2263838cd2f98 | |
parent | d26540493a85fe2f4e85da81504cc0264df0c11f (diff) | |
download | txr-d228557c3c400ba7a81ba0b0fd867ec78bb35015.tar.gz txr-d228557c3c400ba7a81ba0b0fd867ec78bb35015.tar.bz2 txr-d228557c3c400ba7a81ba0b0fd867ec78bb35015.zip |
* 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.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | regex.c | 5 | ||||
-rw-r--r-- | txr.1 | 40 | ||||
-rw-r--r-- | txr.vim | 2 |
6 files changed, 65 insertions, 2 deletions
@@ -1,3 +1,18 @@ +2012-04-10 Kaz Kylheku <kaz@kylheku.com> + + * 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 <kaz@kylheku.com> Port to NetBSD (5.1). @@ -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)); @@ -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); @@ -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); @@ -7274,6 +7274,46 @@ Examples: ;; Replace Hello with Goodbye: (regsub #/Hello/ "Goodbye" "Hello world!") -> "Goodbye world!" +.SS Function regexp + +.TP +Syntax: + + (regexp <obj>) + +.TP +Description: + +The regexp function returns t if <obj> is a compiled regular expression +object. For any other object type, it returns nil. + +.SS Function regex-compile + +.TP +Syntax: + + (regex-compile <form>) + +.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 @@ -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 |