diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-03-09 20:15:15 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-03-09 20:15:15 -0700 |
commit | 0c514dc343033eafde26679f858796549a96cc8d (patch) | |
tree | 1a19a73da0d9611a8e8c9908cc0b8adbc90f1b42 /match.c | |
parent | 01504b7436608a7501bb06f4f1b965607ceb1345 (diff) | |
download | txr-0c514dc343033eafde26679f858796549a96cc8d.tar.gz txr-0c514dc343033eafde26679f858796549a96cc8d.tar.bz2 txr-0c514dc343033eafde26679f858796549a96cc8d.zip |
Fixing broken processing of horizontal matching across
long lines produced by @(freeform). Once the matching
passes about 4000 characters, the "consume_prefix"
function kicks in to save memory. Then any code which is
not properly written to handle this displaced situation
will break.
* match.c (h_text, h_var, h_coll, h_parallel, h_fun): Bugfix.
The recursive calls to match_line return an absolute position.
From this value we must subtract c->base if we are to
compare it with c->pos, or update c->pos. If we use the
absolute value, we are abruptly jumping ahead in the data.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -428,7 +428,7 @@ static val h_text(match_line_ctx *c) val new_pos = cdr(match_line(ml_specline(*c, texts))); if (new_pos) { - c->pos = new_pos; + c->pos = minus(new_pos, c->base); return next_spec_k; } @@ -539,6 +539,8 @@ static val h_var(match_line_ctx *c) return nil; } + new_pos = minus(new_pos, c->base); + LOG_MATCH("var spanning form", new_pos); if (sym) c->bindings = acons(sym, sub_str(c->dataline, c->pos, new_pos), new_bindings); @@ -785,6 +787,8 @@ static val h_coll(match_line_ctx *c) match_line(ml_bindings_specline(*c, new_bindings, spec))); if (until_pos) { + until_pos = minus(until_pos, c->base); + LOG_MATCH("until/last", until_pos); if (sym == last_s) { last_bindings = set_diff(until_last_bindings, @@ -802,6 +806,8 @@ static val h_coll(match_line_ctx *c) val strictly_new_bindings = set_diff(new_bindings, c->bindings, eq_f, nil); val have_new = strictly_new_bindings; + + new_pos = minus(new_pos, c->base); LOG_MATCH("coll", new_pos); for (iter = vars; iter; iter = cdr(iter)) { @@ -935,6 +941,7 @@ static val h_parallel(match_line_ctx *c) if (new_pos) { some_match = t; + new_pos = minus(new_pos, c->base); if (resolve_ub_vars) { val uiter; @@ -1101,7 +1108,7 @@ static val h_fun(match_line_ctx *c) } } - c->pos = success; + c->pos = minus(success, c->base); } } |