diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-01-09 15:44:50 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-01-09 15:44:50 -0800 |
commit | 9fa74517eb0b8252e88f4c636e6e93bca0c9f0be (patch) | |
tree | a14a84ec104a7f625cc9a4c70f2894f8904f2643 | |
parent | d8df8beb2e00517a546d753586d67e14ffa4611d (diff) | |
download | txr-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-- | ChangeLog | 16 | ||||
-rw-r--r-- | eval.c | 6 | ||||
-rw-r--r-- | match.c | 21 | ||||
-rw-r--r-- | match.h | 2 |
4 files changed, 34 insertions, 11 deletions
@@ -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. @@ -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; @@ -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; @@ -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); |