From 97ff23270fa304123ee11ddb773eba68ce8fd223 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 3 Nov 2009 05:35:07 -0800 Subject: Change the freeform line catenation semantics to termination rather than separation. --- ChangeLog | 15 +++++++++++++++ lib.c | 33 +++++++++++++++------------------ lib.h | 2 +- match.c | 6 +++--- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ec8bce6..c18105dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2009-10-21 Kaz Kylheku + + Change the freeform line catenation semantics to termination + rather than separation. + + * lib.h (lazy_str): Declaration updated. + + * lib.c (lazy_str): Tack terminator onto initial prefix + string. Parameter renamed. Also, terminator string cached + in the object. + (lazy_str_force, lazy_str_force_upto): Terminate, rather + than separate. + + * match.c (match_files): sep variable renamed to term. + 2009-10-21 Kaz Kylheku * gc.c (mark_obj): Bugfix: recurse over recently added diff --git a/lib.c b/lib.c index 2bf937aa..8ca4c820 100644 --- a/lib.c +++ b/lib.c @@ -1357,21 +1357,23 @@ obj_t *lazy_stream_cons(obj_t *stream) lazy_stream_func)); } -obj_t *lazy_str(obj_t *list, obj_t *sep, obj_t *limit) +obj_t *lazy_str(obj_t *lst, obj_t *term, obj_t *limit) { obj_t *obj = make_obj(); obj->ls.type = LSTR; - if (nullp(list)) { + term = or2(term, string("\n")); + + if (nullp(lst)) { obj->ls.prefix = null_string; obj->ls.list = nil; } else { - obj->ls.prefix = first(list); - obj->ls.list = rest(list); + obj->ls.prefix = cat_str(list(first(lst), term, nao), nil); + obj->ls.list = rest(lst); limit = if2(limit, minus(limit, one)); } - obj->ls.opts = cons(sep, limit); + obj->ls.opts = cons(term, limit); return obj; } @@ -1382,17 +1384,12 @@ obj_t *lazy_str_force(obj_t *lstr) type_check(lstr, LSTR); lim = cdr(lstr->ls.opts); - if (!lim) { - if (lstr->ls.list) { - lstr->ls.prefix = cat_str(cons(lstr->ls.prefix, lstr->ls.list), - or2(car(lstr->ls.opts), string("\n"))); - lstr->ls.list = nil; - } - } else while (gt(lim, zero) && lstr->ls.list) { - lstr->ls.prefix = cat_str(list(lstr->ls.prefix, car(lstr->ls.list), nao), - or2(car(lstr->ls.opts), string("\n"))); - lstr->ls.list = cdr(lstr->ls.list); - lim = minus(lim, one); + while ((!lim || gt(lim, zero)) && lstr->ls.list) { + obj_t *next = pop(&lstr->ls.list); + obj_t *term = car(lstr->ls.opts); + lstr->ls.prefix = cat_str(list(lstr->ls.prefix, next, term, nao), nil); + if (lim) + lim = minus(lim, one); } if (lim) @@ -1411,8 +1408,8 @@ obj_t *lazy_str_force_upto(obj_t *lstr, obj_t *index) or2(nullp(lim),gt(lim,zero))) { obj_t *next = pop(&lstr->ls.list); - lstr->ls.prefix = cat_str(cons(lstr->ls.prefix, cons(next, nil)), - or2(car(lstr->ls.opts), string("\n"))); + obj_t *term = car(lstr->ls.opts); + lstr->ls.prefix = cat_str(list(lstr->ls.prefix, next, term, nao), nil); if (lim) lim = minus(lim, one); } diff --git a/lib.h b/lib.h index cff8d9bd..81ef1dce 100644 --- a/lib.h +++ b/lib.h @@ -289,7 +289,7 @@ obj_t *vec_set_fill(obj_t *vec, obj_t *fill); obj_t **vecref_l(obj_t *vec, obj_t *ind); obj_t *vec_push(obj_t *vec, obj_t *item); obj_t *lazy_stream_cons(obj_t *stream); -obj_t *lazy_str(obj_t *list, obj_t *sep, obj_t *limit); +obj_t *lazy_str(obj_t *list, obj_t *term, obj_t *limit); obj_t *lazy_str_force_upto(obj_t *lstr, obj_t *index); obj_t *lazy_str_force(obj_t *lstr); obj_t *lazy_str_get_trailing_list(obj_t *lstr, obj_t *index); diff --git a/match.c b/match.c index 08065af1..3df2c08a 100644 --- a/match.c +++ b/match.c @@ -993,10 +993,10 @@ repeat_spec_same_data: } else { obj_t *limit = or2(if2(nump(first(vals)), first(vals)), if2(nump(second(vals)), second(vals))); - obj_t *sep = or2(if2(stringp(first(vals)), first(vals)), - if2(stringp(second(vals)), second(vals))); + obj_t *term = or2(if2(stringp(first(vals)), first(vals)), + if2(stringp(second(vals)), second(vals))); obj_t *ff_specline = rest(first(spec)); - obj_t *ff_dataline = lazy_str(data, sep, limit); + obj_t *ff_dataline = lazy_str(data, term, limit); cons_bind (new_bindings, success, match_line(bindings, ff_specline, ff_dataline, zero, -- cgit v1.2.3