diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | match.c | 31 | ||||
-rw-r--r-- | txr.1 | 12 |
3 files changed, 30 insertions, 21 deletions
@@ -1,3 +1,11 @@ +2011-10-26 Kaz Kylheku <kaz@kylheku.com> + + Fixed lame @(cat) directive, without obsolescence phase. + + * match.c (v_cat): Rewritten. + + * txr.1: Documented. + 2011-10-25 Kaz Kylheku <kaz@kylheku.com> * configure: put in set -u to trap unbound variables, @@ -2242,25 +2242,24 @@ static val v_set(match_files_ctx c, match_files_ctx *cout) static val v_cat(match_files_ctx c, match_files_ctx *cout) { spec_bind (specline, spec_linenum, first_spec, c.spec); - val iter; + val sym = second(first_spec); + val sep_form = third(first_spec); - for (iter = rest(first_spec); iter; iter = rest(iter)) { - val sym = first(iter); + if (rest(specline)) + sem_error(spec_linenum, lit("cat: obsolete syntax")); - if (!bindable(sym)) { - sem_error(spec_linenum, - lit("cat: ~s is not a bindable symbol"), sym, nao); + if (!bindable(sym)) { + sem_error(spec_linenum, + lit("cat: ~s is not a bindable symbol"), sym, nao); + } else { + val existing = assoc(c.bindings, sym); + if (existing) { + val sep = if3(sep_form, + cdr(eval_form(spec_linenum, sep_form, c.bindings)), + lit(" ")); + *cdr_l(existing) = cat_str(flatten(cdr(existing)), sep); } else { - val existing = assoc(c.bindings, sym); - val sep = nil; - - if (rest(specline)) { - val sub = subst_vars(rest(specline), c.bindings, nil); - sep = cat_str(sub, nil); - } - - if (existing) - *cdr_l(existing) = cat_str(flatten(cdr(existing)), sep); + sem_error(spec_linenum, lit("cat: unbound variable ~s"), sym, nao); } } @@ -2043,15 +2043,17 @@ levels of nesting such that elements are at the appropriate depth. .SS The Cat Directive The @(cat) directive converts a list variable into a single -piece of text. Optionally, a separating piece of text can be inserted -in between the elements. This piece is written to the right of -the @(cat) directive, and spans to the end of the line. It may -contain variable substitutions. +piece of text. The syntax is: + + @(cat VAR [ SEP ]) + +The SEP argument specifies a separating piece of text. If no separator +is specified, then a single space is used. Example: pattern: @(coll)@{a /[^ ]+/}@(end) - @(cat a): + @(cat a ":") data: 1 2 3 4 5 result: a="1:2:3:4:5" |