diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | match.c | 2 | ||||
-rw-r--r-- | regex.c | 5 | ||||
-rw-r--r-- | regex.h | 1 | ||||
-rw-r--r-- | txr.1 | 5 |
5 files changed, 22 insertions, 2 deletions
@@ -1,3 +1,14 @@ +2009-10-18 Kaz Kylheku <kkylheku@gmail.com> + + Trivial change allows regexps to be bound to variables, + and used for matching. This Just Works because of + the way match_line treats variables. + + * match.c (eval_form): Check for a regexp form and return + it as a value representing itself. + * regex.c (regexp): New function. + * regex.h (regexp): Declared. + 2009-10-17 Kaz Kylheku <kkylheku@gmail.com> * deps.mk: Updated. @@ -604,6 +604,8 @@ obj_t *eval_form(obj_t *form, obj_t *bindings) else if (consp(form)) { if (car(form) == quasi) { return cons(t, cat_str(subst_vars(rest(form), bindings), nil)); + } else if (regexp(car(form))) { + return cons(t, form); } else { obj_t *subforms = mapcar(bind2other(func_n2(eval_form), bindings), form); @@ -593,6 +593,11 @@ obj_t *regex_compile(obj_t *regex_sexp) return cobj(pnfa, regex, ®ex_obj_ops); } +obj_t *regexp(obj_t *obj) +{ + return (obj->co.type == COBJ && obj->co.cls == regex) ? t : nil; +} + nfa_t *regex_nfa(obj_t *reg) { assert (reg->co.type == COBJ && reg->co.cls == regex); @@ -101,6 +101,7 @@ nfa_t nfa_compile_regex(obj_t *regex); void nfa_free(nfa_t); long nfa_run(nfa_t nfa, const char *str); obj_t *regex_compile(obj_t *regex_sexp); +obj_t *regexp(obj_t *); nfa_t *regex_nfa(obj_t *); obj_t *search_regex(obj_t *haystack, obj_t *needle_regex, obj_t *start_num, obj_t *from_end); @@ -1419,7 +1419,8 @@ to match B, or the bind fails. Matching means that either found as substructure within the other. The right hand side does not have to be a variable. It may be some other -object, like a string, or list of strings, et cetera. For instance +object, like a string, quasiliteral, regexp, or list of strings, et cetera. For +instance @(bind A "ab\tc") @@ -1883,7 +1884,7 @@ matches an input line "begin". A function is invoked by compound directive whose first symbol is the name of that function. Additional elements in the directive are the arguments. Arguments may be symbols, or other objects like string and character -literals. +literals, quasiliterals ore regular expressions. Example: |