diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-03-22 19:16:06 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-03-22 19:16:06 -0700 |
commit | 8f57057a347cd20a3a04156ca1caa810509e6e09 (patch) | |
tree | c3535adee3b9f213569bcec5a858509b3a2948da /match.c | |
parent | 6e06daed77cb0d3f34643975b50026e3e3699966 (diff) | |
download | txr-8f57057a347cd20a3a04156ca1caa810509e6e09.tar.gz txr-8f57057a347cd20a3a04156ca1caa810509e6e09.tar.bz2 txr-8f57057a347cd20a3a04156ca1caa810509e6e09.zip |
Merge some repeated code.
* match.c (maybe_next): New static function.
(v_block, v_if): Replace block of code with call to
maybe_next.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 51 |
1 files changed, 20 insertions, 31 deletions
@@ -2243,6 +2243,23 @@ val freeform_prepare(val vals, match_files_ctx *c, match_line_ctx *mlc) return limit; } +static val maybe_next(match_files_ctx *c, val match_result) +{ + cons_bind (new_bindings, success, match_result); + + 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; +} static val v_block(match_files_ctx *c) { @@ -2260,22 +2277,7 @@ static val v_block(match_files_ctx *c) result = match_files(mf_spec(*c, spec)); uw_block_end; - { - cons_bind (new_bindings, success, result); - - 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 maybe_next(c, result); } } @@ -3663,21 +3665,8 @@ static val v_if(match_files_ctx *c) 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; - } + if (eval_with_bindings(expr, c->spec, c->bindings, specline)) + return maybe_next(c, match_files(mf_spec(*c, spec))); } return next_spec_k; |