summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--match.c2
-rw-r--r--regex.c5
-rw-r--r--regex.h1
-rw-r--r--txr.15
5 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 44074225..9fa42564 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/match.c b/match.c
index 47fc31a7..d065cc1d 100644
--- a/match.c
+++ b/match.c
@@ -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);
diff --git a/regex.c b/regex.c
index 51c95bc4..926ae4fd 100644
--- a/regex.c
+++ b/regex.c
@@ -593,6 +593,11 @@ obj_t *regex_compile(obj_t *regex_sexp)
return cobj(pnfa, regex, &regex_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);
diff --git a/regex.h b/regex.h
index 10fcf4b4..5f2d5021 100644
--- a/regex.h
+++ b/regex.h
@@ -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);
diff --git a/txr.1 b/txr.1
index d4cd6183..4aea4a82 100644
--- a/txr.1
+++ b/txr.1
@@ -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: