summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-02-18 17:43:56 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-02-18 17:43:56 -0800
commitd14ddd48c53f3d9ec960782c75f657a627456d22 (patch)
treef966df8f17c1a532a41ffa7c749edb0fd95418f5 /eval.c
parent3b1e713d392d607a37e9f6d1520c4f9f584d014d (diff)
downloadtxr-d14ddd48c53f3d9ec960782c75f657a627456d22.tar.gz
txr-d14ddd48c53f3d9ec960782c75f657a627456d22.tar.bz2
txr-d14ddd48c53f3d9ec960782c75f657a627456d22.zip
Allow braced output variables to actually be arbitrary substitutions.
* eval.c (subst_vars): Treat the variable as an arbitrary expression rather than just a symbol. * match.c (subst_vars): Likewise. * parser.y (o_var): Further simplification. The first item in an output var is an expr and not an IDENT. * txr.1: Updated. * txr.vim: Likewise.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/eval.c b/eval.c
index 3a072c77..9380df06 100644
--- a/eval.c
+++ b/eval.c
@@ -1118,29 +1118,23 @@ static val subst_vars(val forms, val env)
val sym = first(form);
if (sym == var_s) {
- val sym = second(form);
+ val expr = second(form);
val pat = third(form);
val modifiers = fourth(form);
- val pair = lookup_var(env, sym);
-
- if (pair) {
- val str = cdr(pair);
-
- if (!stringp(str) && !listp(str))
- str = format(nil, lit("~a"), str, nao);
-
- if (pat)
- forms = cons(str, cons(pat, rest(forms)));
- else if (modifiers)
- forms = cons(format_field(str, modifiers, nil,
- curry_123_1(func_n3(eval), env, form)),
- rest(forms));
- else
- forms = cons(str, rest(forms));
- continue;
- }
- uw_throwf(query_error_s, lit("unbound variable ~a"),
- sym, nao);
+ val str = eval(expr, env, form);
+
+ if (!stringp(str) && !listp(str))
+ str = format(nil, lit("~a"), str, nao);
+
+ if (pat)
+ forms = cons(str, cons(pat, rest(forms)));
+ else if (modifiers)
+ forms = cons(format_field(str, modifiers, nil,
+ curry_123_1(func_n3(eval), env, form)),
+ rest(forms));
+ else
+ forms = cons(str, rest(forms));
+ continue;
} else if (sym == quasi_s) {
val nested = subst_vars(rest(form), env);
list_collect_append(iter, nested);