diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-12-05 23:47:58 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-12-05 23:47:58 -0800 |
commit | 43fa874fd295b2c765cddd14939a60a47e190148 (patch) | |
tree | 19e9205efe84ec5b66e1b0b47f8bf732edde9909 | |
parent | f128b3e3f1ab9fb724d09486b59ae2a2b4cab29c (diff) | |
download | txr-43fa874fd295b2c765cddd14939a60a47e190148.tar.gz txr-43fa874fd295b2c765cddd14939a60a47e190148.tar.bz2 txr-43fa874fd295b2c765cddd14939a60a47e190148.zip |
* regex.c (regex_compile): Handle string input.
* regex.h (regex_compile): Don't call argument
regex_sexp, since it can be a string.
* txr.1: Updated.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | regex.c | 6 | ||||
-rw-r--r-- | regex.h | 2 | ||||
-rw-r--r-- | txr.1 | 15 |
4 files changed, 26 insertions, 6 deletions
@@ -1,5 +1,14 @@ 2013-12-05 Kaz Kylheku <kaz@kylheku.com> + * regex.c (regex_compile): Handle string input. + + * regex.h (regex_compile): Don't call argument + regex_sexp, since it can be a string. + + * txr.1: Updated. + +2013-12-05 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): Registered regex_parse as new intrinsic function and std_null as new variable. @@ -35,6 +35,7 @@ #include <limits.h> #include "config.h" #include "lib.h" +#include "parser.h" #include "unwind.h" #include "regex.h" #include "txr.h" @@ -1614,7 +1615,10 @@ static val regex_requires_dv(val exp) val regex_compile(val regex_sexp) { - if (opt_derivative_regex || regex_requires_dv(regex_sexp)) { + if (stringp(regex_sexp)) { + regex_sexp = regex_parse(regex_sexp, nil); + return if2(regex_sexp, regex_compile(regex_sexp)); + } else if (opt_derivative_regex || regex_requires_dv(regex_sexp)) { return cons(compiled_regex_s, cons(dv_compile_regex(regex_sexp), nil)); } else { nfa_t *pnfa = (nfa_t *) chk_malloc(sizeof *pnfa); @@ -27,7 +27,7 @@ extern val space_k, digit_k, word_char_k; extern val cspace_k, cdigit_k, cword_char_k; -val regex_compile(val regex_sexp); +val regex_compile(val regex); val regexp(val); val search_regex(val haystack, val needle_regex, val start_num, val from_end); val match_regex(val str, val regex, val pos); @@ -9348,16 +9348,20 @@ object. For any other object type, it returns nil. .TP Syntax: - (regex-compile <form>) + (regex-compile <form-or-string>) .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. +expressed as a Lisp data structure representing an abstract syntax tree, or +else a regular expression specified as a character string, and compiles it to a +regular expression object. -Suitable source code is produced by regex-parse. +If <form-or-string> is a character string, it is parsed to an +abstract syntax tree first, if by a call to (regex-parse <form-or-string>). +If the parse is successful (the result is not nil) then +it is compiled by a recursive call to regex-compile. .TP Examples: @@ -9372,6 +9376,9 @@ Examples: ;; #/a|b|c/ (regex-compile '(or (or #\ea #\eb) #\ec)) + ;; string + (regex-compile "a|b|c") + .SS Function regex-parse .TP |