diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-20 12:02:13 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-20 12:02:13 -0800 |
commit | 71cacde9c896a1532247a349a298e68fd20500a8 (patch) | |
tree | 685d2fe504ac2b1cab28144f386e72039992b635 /match.c | |
parent | 811b58e8f70fac421a905a2b627449dfd079958c (diff) | |
download | txr-71cacde9c896a1532247a349a298e68fd20500a8.tar.gz txr-71cacde9c896a1532247a349a298e68fd20500a8.tar.bz2 txr-71cacde9c896a1532247a349a298e68fd20500a8.zip |
Relaxing :vars in collect/coll a little bit.
* match.c (h_coll, v_collect): Only throw an error about
missing required variables if the collect iteration collected some new
variables. This allows strict collects with :vars to have
some cases which explicitly match and skip unwanted material,
without binding variables. Also, print all missing variables in the
diagnostic.
* txr.1: Mention this special exception.
* RELNOTES: Updated.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -740,8 +740,10 @@ static val h_coll(match_line_ctx c, match_line_ctx *cout) } if (new_pos) { + list_collect_decl (missing, ptail); val strictly_new_bindings = set_diff(new_bindings, c.bindings, eq_f, nil); + val have_new = strictly_new_bindings; LOG_MATCH("coll", new_pos); for (iter = vars; iter; iter = cdr(iter)) { @@ -750,14 +752,17 @@ static val h_coll(match_line_ctx c, match_line_ctx *cout) if (!exists) { if (dfl == noval_s) - sem_error(elem, lit("coll failed to bind ~a"), - var, nao); + list_collect (ptail, var); else strictly_new_bindings = acons(strictly_new_bindings, var, dfl); } } + if (have_new && missing) + sem_error(elem, lit("collect failed to bind ~a"), + missing, nao); + for (iter = strictly_new_bindings; iter; iter = cdr(iter)) { val binding = car(iter); @@ -2305,8 +2310,10 @@ static val v_collect(match_files_ctx *c) } if (success) { + list_collect_decl (missing, ptail); val strictly_new_bindings = set_diff(new_bindings, c->bindings, eq_f, nil); + val have_new = strictly_new_bindings; debuglf(specline, lit("collect matched ~a:~a"), first(c->files), c->data_lineno, nao); @@ -2317,14 +2324,17 @@ static val v_collect(match_files_ctx *c) if (!exists) { if (dfl == noval_s) - sem_error(specline, lit("collect failed to bind ~a"), - var, nao); + list_collect (ptail, var); else strictly_new_bindings = acons(strictly_new_bindings, var, dfl); } } + if (have_new && missing) + sem_error(specline, lit("collect failed to bind ~a"), + missing, nao); + for (iter = strictly_new_bindings; iter; iter = cdr(iter)) { val binding = car(iter); |