summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-02-28 23:46:53 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-02-28 23:46:53 -0800
commitaec0b3b3645d241ea8ad1f06dd64716b7d9c3c00 (patch)
treedc438ef7b99e4cea25d8bbfa8d88cee835b1c595 /match.c
parent0e1b6b6f1e2ea9b420e148b3faf65c34790b7bcd (diff)
downloadtxr-aec0b3b3645d241ea8ad1f06dd64716b7d9c3c00.tar.gz
txr-aec0b3b3645d241ea8ad1f06dd64716b7d9c3c00.tar.bz2
txr-aec0b3b3645d241ea8ad1f06dd64716b7d9c3c00.zip
* match.c (do_match_line): Function takes new argument, "completely".
The check for completely matching a line is now done within do_match_line. (match_line): Pass nil to do_match_line, specifying that a prefix match is okay. (match_line_completely): New interface to do_match_line, which requests a match to the end of the line. (v_freeform): Pass nil to do_match_line: freeform needs incomplete match semantics. (match_files): Use match_line_completely instead of match_line. By doing it this way, we do not need to compute the length of the original line and compare it to the absolute position. This saves time and memory since computing the length of a lazy string forces it.
Diffstat (limited to 'match.c')
-rw-r--r--match.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/match.c b/match.c
index 78ff23d0..736e2bed 100644
--- a/match.c
+++ b/match.c
@@ -371,7 +371,7 @@ static match_line_ctx ml_bindings_specline(match_line_ctx c, val bindings,
return nc;
}
-static val do_match_line(match_line_ctx *c);
+static val do_match_line(match_line_ctx *c, val completely);
static val match_line(match_line_ctx c);
typedef val (*h_match_func)(match_line_ctx *c);
@@ -1090,7 +1090,7 @@ static match_files_ctx mf_all(val spec, val files, val bindings,
static val v_fun(match_files_ctx *c);
-static val do_match_line(match_line_ctx *c)
+static val do_match_line(match_line_ctx *c, val completely)
{
debug_enter;
@@ -1200,15 +1200,27 @@ static val do_match_line(match_line_ctx *c)
c->specline = cdr(c->specline);
}
+ if (completely && length_str_gt(c->dataline, c->pos)) {
+ debuglf(c->specline, lit("spec only matches line to position ~a: ~a"),
+ plus(c->pos, c->base), c->dataline, nao);
+ debug_return (nil);
+ }
+
debug_return (cons(c->bindings, plus(c->pos, c->base)));
debug_leave;
}
static val match_line(match_line_ctx c)
{
- return do_match_line(&c);
+ return do_match_line(&c, nil);
+}
+
+static val match_line_completely(match_line_ctx c)
+{
+ return do_match_line(&c, t);
}
+
val format_field(val obj, val modifier, val filter, val eval_fun)
{
val n = zero, sep = lit(" ");
@@ -2054,7 +2066,7 @@ static val v_freeform(match_files_ctx *c)
c->data = nil;
{
- cons_bind (new_bindings, success, do_match_line(&mlc));
+ cons_bind (new_bindings, success, do_match_line(&mlc, nil));
if (!success) {
debuglf(specline, lit("freeform match failure"), nao);
@@ -3509,14 +3521,9 @@ repeat_spec_same_data:
val dataline = first(c.data);
cons_bind (new_bindings, success,
- match_line(ml_all(c.bindings, specline, dataline, zero,
- c.data_lineno, first(c.files))));
-
- if (numberp(success) && length_str_gt(dataline, success)) {
- debuglf(specline, lit("spec only matches line to position ~a: ~a"),
- success, dataline, nao);
- debug_return (nil);
- }
+ match_line_completely(ml_all(c.bindings, specline,
+ dataline, zero,
+ c.data_lineno, first(c.files))));
if (!success)
debug_return (nil);