summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-11-17 06:41:38 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-11-20 16:17:18 -0800
commita25862d24050e8ff6e8eb1077715abac4afe5ff4 (patch)
tree7b292a9cb0866475ceedca6737b323b06e8d5dd9 /match.c
parent559c24b4900f70e893902dbac99d7a8a113fb6f0 (diff)
downloadtxr-a25862d24050e8ff6e8eb1077715abac4afe5ff4.tar.gz
txr-a25862d24050e8ff6e8eb1077715abac4afe5ff4.tar.bz2
txr-a25862d24050e8ff6e8eb1077715abac4afe5ff4.zip
@(rep) as shorthand for @(coll :vars nil).
* match.c (h_coll): Check for rep symbol, and handle similarly to v_coll. Use symbol in error message. (dir_tables_init): Bind rep symbol to h_coll. * parser.y (elems): Don't generate rep_elem phrase structure for the sake of catching "rep outside of output"; this production now conflicts with the intent to allow this. (elem): Add various REP productions which clones of COLL. * txr.1: Documented new @(rep) usage.
Diffstat (limited to 'match.c')
-rw-r--r--match.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/match.c b/match.c
index 1577b735..71ea60c2 100644
--- a/match.c
+++ b/match.c
@@ -808,6 +808,7 @@ static val h_skip(match_line_ctx *c)
static val h_coll(match_line_ctx *c)
{
val elem = first(c->specline);
+ val op_sym = first(elem);
val coll_specline = second(elem);
val until_last_specline = third(elem);
val args = fourth(elem);
@@ -833,6 +834,13 @@ static val h_coll(match_line_ctx *c)
cnum timescounter = 0, charscounter = 0;
val iter;
+ if (op_sym == rep_s) {
+ if (have_vars)
+ sem_error(elem, lit("~s: coll takes :vars, rep does not"),
+ op_sym, nao);
+ have_vars = t;
+ }
+
vars = vars_to_bindings(elem, vars, c->bindings);
if (((times || maxtimes) && ctimax == 0) || (chars && cchars == 0))
@@ -893,8 +901,8 @@ static val h_coll(match_line_ctx *c)
}
if (have_new && missing)
- sem_error(elem, lit("collect failed to bind ~a"),
- missing, nao);
+ sem_error(elem, lit("~s failed to bind ~a"),
+ op_sym, missing, nao);
for (iter = strictly_new_bindings; iter; iter = cdr(iter))
{
@@ -4192,6 +4200,7 @@ static void dir_tables_init(void)
sethash(h_directive_table, var_s, cptr(coerce(mem_t *, h_var)));
sethash(h_directive_table, skip_s, cptr(coerce(mem_t *, h_skip)));
sethash(h_directive_table, coll_s, cptr(coerce(mem_t *, h_coll)));
+ sethash(h_directive_table, rep_s, cptr(coerce(mem_t *, h_coll)));
sethash(h_directive_table, flatten_s, cptr(coerce(mem_t *, hv_trampoline)));
sethash(h_directive_table, forget_s, cptr(coerce(mem_t *, hv_trampoline)));
sethash(h_directive_table, local_s, cptr(coerce(mem_t *, hv_trampoline)));