summaryrefslogtreecommitdiffstats
path: root/match.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 /match.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 'match.c')
-rw-r--r--match.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/match.c b/match.c
index d921757e..d253913a 100644
--- a/match.c
+++ b/match.c
@@ -1316,37 +1316,31 @@ static val subst_vars(val spec, val bindings, val filter)
val sym = first(elem);
if (sym == var_s) {
- val sym = second(elem);
+ val expr = second(elem);
val pat = third(elem);
val modifiers = fourth(elem);
- val pair = assoc(sym, bindings);
+ val str = txeval(spec, expr, bindings);
- if (pair) {
- val str = cdr(pair);
+ if (!stringp(str) && !listp(str))
+ str = format(nil, lit("~a"), str, nao);
- if (!stringp(str) && !listp(str))
- str = format(nil, lit("~a"), str, nao);
+ if (pat)
+ spec = cons(pat, rest(spec));
- if (pat)
- spec = cons(pat, rest(spec));
-
- if (modifiers) {
- spec = cons(format_field(str, modifiers, filter,
- curry_123_2(func_n3(txeval), spec, bindings)),
- rest(spec));
- } else {
- if (listp(str))
- str = cat_str(mapcar(func_n1(tostringp), str), lit(" "));
- else
- str = if3(stringp(str), str, tostringp(str));
-
- spec = cons(filter_string(filter, str), rest(spec));
- }
+ if (modifiers) {
+ spec = cons(format_field(str, modifiers, filter,
+ curry_123_2(func_n3(txeval), spec, bindings)),
+ rest(spec));
+ } else {
+ if (listp(str))
+ str = cat_str(mapcar(func_n1(tostringp), str), lit(" "));
+ else
+ str = if3(stringp(str), str, tostringp(str));
- continue;
+ spec = cons(filter_string(filter, str), rest(spec));
}
- uw_throwf(query_error_s, lit("unbound variable ~a"),
- sym, nao);
+
+ continue;
} else if (sym == quasi_s) {
val nested = subst_vars(rest(elem), bindings, filter);
list_collect_append(iter, nested);