From 6e06daed77cb0d3f34643975b50026e3e3699966 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 22 Mar 2016 17:10:09 -0700 Subject: New semantics for @(if) directive. * eval.h (if_s): Declared. * match.c (v_if): New static function. (dir_tables_init): Register v_if in v_directive_table under if symbol. * parser.y (IF): Token assigned to type. (if_clause, elif_clauses_opt, else_clause_opt): New syntactic representation, understood by v_if. * txr.1: Documented if semantics more precisely, dropped the text about it being syntactic sugar for a cases with require, added compatibility note. --- match.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'match.c') diff --git a/match.c b/match.c index 4e5ed362..0747b011 100644 --- a/match.c +++ b/match.c @@ -3656,6 +3656,33 @@ static val v_require(match_files_ctx *c) return next_spec_k; } +static val v_if(match_files_ctx *c) +{ + spec_bind (specline, first_spec, c->spec); + val args = rest(first_spec); + + for (; args; args = cdr(args)) { + cons_bind (expr, spec, car(args)); + if (eval_with_bindings(expr, c->spec, c->bindings, specline)) { + cons_bind (new_bindings, success, match_files(mf_spec(*c, spec))); + if (!success) { + return nil; + } else if (success == t) { + c->data = nil; + } else { + cons_bind (new_data, new_line, success); + c->data = new_data; + c->data_lineno = new_line; + } + + c->bindings = new_bindings; + return next_spec_k; + } + } + + return next_spec_k; +} + static val v_assert(match_files_ctx *c) { spec_bind (specline, first_spec, c->spec); @@ -4182,6 +4209,7 @@ static void dir_tables_init(void) sethash(v_directive_table, eof_s, cptr(coerce(mem_t *, v_eof))); sethash(v_directive_table, do_s, cptr(coerce(mem_t *, v_do))); sethash(v_directive_table, require_s, cptr(coerce(mem_t *, v_require))); + sethash(v_directive_table, if_s, cptr(coerce(mem_t *, v_if))); sethash(v_directive_table, assert_s, cptr(coerce(mem_t *, v_assert))); sethash(v_directive_table, load_s, cptr(coerce(mem_t *, v_load))); sethash(v_directive_table, close_s, cptr(coerce(mem_t *, v_close))); -- cgit v1.2.3