summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-01-09 15:44:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-01-09 15:44:50 -0800
commit9fa74517eb0b8252e88f4c636e6e93bca0c9f0be (patch)
treea14a84ec104a7f625cc9a4c70f2894f8904f2643
parentd8df8beb2e00517a546d753586d67e14ffa4611d (diff)
downloadtxr-9fa74517eb0b8252e88f4c636e6e93bca0c9f0be.tar.gz
txr-9fa74517eb0b8252e88f4c636e6e93bca0c9f0be.tar.bz2
txr-9fa74517eb0b8252e88f4c636e6e93bca0c9f0be.zip
Non-broken way to achieve intent of previous commit.
* eval.c (subst_vars): Do not evaluate modifiers as an argument list locally. Pass form-evaluating function to format_field. * match.c (format_field): Modified to accept new argument, a one-argument function for reducing a form to a value. Error checking for invalid modifiers made stricter. (subst_vars): Do not evaluate modifiers as an argument list. Pass form-evaluating function to format_field. * match.h (format_field): Declaration updated.
-rw-r--r--ChangeLog16
-rw-r--r--eval.c6
-rw-r--r--match.c21
-rw-r--r--match.h2
4 files changed, 34 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f87c46b..11db5c38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2012-01-09 Kaz Kylheku <kaz@kylheku.com>
+ Non-broken way to achieve intent of previous commit.
+
+ * eval.c (subst_vars): Do not evaluate modifiers
+ as an argument list locally. Pass form-evaluating
+ function to format_field.
+
+ * match.c (format_field): Modified to accept new argument,
+ a one-argument function for reducing a form to a value.
+ Error checking for invalid modifiers made stricter.
+ (subst_vars): Do not evaluate modifiers as an argument
+ list. Pass form-evaluating function to format_field.
+
+ * match.h (format_field): Declaration updated.
+
+2012-01-09 Kaz Kylheku <kaz@kylheku.com>
+
* eval.c (subst_vars): Evaluate the
modifiers, so expressions can be used.
diff --git a/eval.c b/eval.c
index 70711b45..11998a81 100644
--- a/eval.c
+++ b/eval.c
@@ -744,7 +744,7 @@ static val subst_vars(val forms, val env)
if (sym == var_s) {
val sym = second(form);
val pat = third(form);
- val modifiers = eval_args(fourth(form), env, form);
+ val modifiers = fourth(form);
val pair = lookup_var(env, sym);
if (pair) {
@@ -756,7 +756,9 @@ static val subst_vars(val forms, val env)
if (pat)
forms = cons(str, cons(pat, rest(forms)));
else if (modifiers)
- forms = cons(format_field(str, modifiers, nil), rest(forms));
+ forms = cons(format_field(str, modifiers, nil,
+ curry_123_1(func_n3(eval), env, form)),
+ rest(forms));
else
forms = cons(str, rest(forms));
continue;
diff --git a/match.c b/match.c
index 1dece256..25e8561d 100644
--- a/match.c
+++ b/match.c
@@ -1203,7 +1203,7 @@ static val match_line(match_line_ctx c)
return cons(c.bindings, c.pos);
}
-val format_field(val string_or_list, val modifier, val filter)
+val format_field(val string_or_list, val modifier, val filter, val eval_fun)
{
val n = zero;
val plist = nil;
@@ -1213,14 +1213,21 @@ val format_field(val string_or_list, val modifier, val filter)
for (; modifier; pop(&modifier)) {
val item = first(modifier);
- if (fixnump(item))
- n = item;
if (regexp(item))
uw_throw(query_error_s, lit("format_field: regex modifier in output"));
if (keywordp(item)) {
plist = modifier;
break;
}
+
+ {
+ val v = funcall1(eval_fun, item);
+ if (fixnump(v))
+ n = v;
+ else
+ uw_throwf(query_error_s, lit("format_field: bad modifier object: ~s"),
+ item, nao);
+ }
}
{
@@ -1277,10 +1284,6 @@ static val subst_vars(val spec, val bindings, val filter)
val modifiers = fourth(elem);
val pair = assoc(sym, bindings);
- if (modifiers)
- modifiers = mapcar(curry_123_2(func_n3(txeval), spec, bindings),
- modifiers);
-
if (pair) {
val str = cdr(pair);
@@ -1290,7 +1293,9 @@ static val subst_vars(val spec, val bindings, val filter)
if (pat)
spec = cons(filter_string(filter, str), cons(pat, rest(spec)));
else if (modifiers)
- spec = cons(format_field(str, modifiers, filter), rest(spec));
+ spec = cons(format_field(str, modifiers, filter,
+ curry_123_2(func_n3(txeval), spec, bindings)),
+ rest(spec));
else
spec = cons(filter_string(filter, str), rest(spec));
continue;
diff --git a/match.h b/match.h
index bb69a030..f0398ebe 100644
--- a/match.h
+++ b/match.h
@@ -25,7 +25,7 @@
*/
extern val text_s, choose_s, gather_s, do_s, mod_s, modlast_s, counter_k;
-val format_field(val string_or_list, val modifier, val filter);
+val format_field(val string_or_list, val modifier, val filter, val eval_fun);
val match_funcall(val name, val arg, val other_args);
int extract(val spec, val filenames, val bindings);
void match_init(void);