From f4a6c56c8e8841c1991c1bb44546681ccbdb8f3a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 25 Mar 2014 22:10:31 -0700 Subject: * eval.c (me_quasilist): New static function. (eval_init): Register me_quasilist as quasilist macro expander. * lib.c (quasilist_s): New global variable. (obj_init): quasilist_s initialized. * lib.h (quasilist_s): Declared. * match.c (do_txreval): Handle quasilist syntax. * parser.l (QWLIT): New exclusive state. Extend lexical grammar to transition to QWLIT state upon the #` or #*` sequence which kicks off a word literal, and in that state, piecewise lexically analyze the QLL, mostly by borrowing rules from quasiliterals. * parser.y (QWORDS, QWSPLICE): New tokens. (n_exprs): Integrate splicing form of QLL syntax. (n_expr): Integrate non-splicing form of QLL syntax. (litchars): Propagate line number info. (quasilit): Fix "string literal" wording in error message. * txr.1: Introduced WLL abbreviation for word list literals, cleaned up the text a little, and documented QLL's. --- match.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'match.c') diff --git a/match.c b/match.c index 9b2a6900..ae37a56d 100644 --- a/match.c +++ b/match.c @@ -1449,19 +1449,29 @@ static val do_txeval(val spec, val form, val bindings, val allow_unbound) ret = cdr(binding); } } else if (consp(form)) { - if (first(form) == quasi_s) { + val sym = first(form); + if (sym == quasi_s) { uw_env_begin; uw_set_match_context(cons(spec, bindings)); ret = cat_str(subst_vars(rest(form), bindings, nil), nil); uw_env_end; - } else if (regexp(car(form))) { + } else if (sym == quasilist_s) { + uw_env_begin; + val iter; + list_collect_decl (out, tail); + uw_set_match_context(cons(spec, bindings)); + for (iter = rest(form); iter != nil; iter = cdr(iter)) + list_collect(tail, subst_vars(cdr(car(iter)), bindings, nil)); + ret = out; + uw_env_end; + } else if (regexp(sym)) { ret = form; - } else if (first(form) == var_s) { + } else if (sym == var_s) { uw_env_begin; uw_set_match_context(cons(spec, bindings)); ret = eval(second(form), make_env(bindings, nil, nil), form); uw_env_end; - } else if (first(form) == expr_s) { + } else if (sym == expr_s) { uw_env_begin; uw_set_match_context(cons(spec, bindings)); ret = eval(rest(form), make_env(bindings, nil, nil), form); -- cgit v1.2.3