summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--match.c19
-rw-r--r--txr.127
3 files changed, 50 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 7cdbfcb5..ac50250c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-05-15 Kaz Kylheku <kaz@kylheku.com>
+
+ * match.c (match_fun): Support debug stop on the function
+ prior to the call. The first data line number is 1, not zero,
+ if there is data.
+
+ * txr.1: Added usage example for match-fun.
+
2013-05-14 Kaz Kylheku <kaz@kylheku.com>
* txr.1: Documented time and url encoding/decoding functions.
diff --git a/match.c b/match.c
index e1d74399..410bd05a 100644
--- a/match.c
+++ b/match.c
@@ -3698,14 +3698,23 @@ val match_filter(val name, val arg, val other_args)
val match_fun(val name, val args, val input, val files)
{
- val spec = cons(cons(cons(name, args), nil), nil);
+ val call = cons(name, args);
+ val spec = cons(cons(call, nil), nil);
val in_bindings = cdr(uw_get_match_context());
val data = if3(streamp(input),
lazy_stream_cons(input),
input);
/* TODO: pass through source location context */
- match_files_ctx c = mf_all(spec, files, in_bindings, data, num(0));
- val ret = v_fun(&c);
+ match_files_ctx c = mf_all(spec, files, in_bindings, data,
+ if3(data, one, zero));
+ val ret;
+
+ debug_enter;
+
+ debug_check(call, c.bindings, if2(consp(c.data), car(c.data)),
+ c.data_lineno, nil, nil);
+
+ ret = v_fun(&c);
if (ret == nil)
return nil;
@@ -3713,7 +3722,9 @@ val match_fun(val name, val args, val input, val files)
if (ret == decline_k)
sem_error(nil, lit("match_fun: function ~s not found"), name, nao);
- return cons(c.bindings, cons(c.data, c.data_lineno));
+ debug_return (cons(c.bindings, if3(c.data, cons(c.data, c.data_lineno), t)));
+
+ debug_leave;
}
int extract(val spec, val files, val predefined_bindings)
diff --git a/txr.1 b/txr.1
index 39742b30..fa96fffb 100644
--- a/txr.1
+++ b/txr.1
@@ -10358,6 +10358,33 @@ is one of two values. If the entire input was processed, the cdr field holds
the symbol t. Otherwise it holds another cons cell whose car is the remainder
of the list of lines which were not matched, and the cdr is the line number.
+.TP
+Example:
+
+ @(define foo (x y))
+ @x:@y
+ @line
+ @(end)
+ @(do
+ (format t "~s\n"
+ (match-fun 'foo '(a b) '("alpha:beta" "gamma" "omega") nil)))
+
+ Output:
+ (((a . "alpha") (b . "beta")) ("omega") . 3)
+
+In the above example, the pattern function foo is called with arguments (a b).
+These are unbound variables, so they correspond to parameters x and y
+of the function. If x and y get bound, those values propagate to a and b.
+The data being matched consists of the lines "alpha:beta", "gamma" and
+"omega". Inside foo, x and y bind to "alpha" and "beta", and then the
+line variable binds t "gamma". The input stream is left with "omega".
+
+Hence, the return value consists of the bindings of x and y transferred to a
+and b, and the second cons cell giving information about the rest of the
+stream: it is the part starting at "omega", which is line 3. Note that the
+binding for for line variable does not propagate out of the pattern function
+foo; it is local inside it.
+
.SH DEBUGGING FUNCTIONS
.SS Functions source-loc and source-loc-str