summaryrefslogtreecommitdiffstats
path: root/match.c
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 /match.c
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.
Diffstat (limited to 'match.c')
-rw-r--r--match.c21
1 files changed, 13 insertions, 8 deletions
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;