diff options
-rw-r--r-- | ChangeLog | 26 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | match.c | 33 | ||||
-rw-r--r-- | tests/004/query-1.expected | 3 | ||||
-rw-r--r-- | tests/004/query-1.txr | 67 | ||||
-rw-r--r-- | txr.1 | 2 | ||||
-rw-r--r-- | txr.c | 2 |
7 files changed, 120 insertions, 14 deletions
@@ -1,6 +1,30 @@ 2009-10-17 Kaz Kylheku <kkylheku@gmail.com> - Version 016 + Version 018 + + Bugfixes: mistakes in debugging calls; infinite looping + bug in collect; skip directive not advancing match + by proper number of lines bug. + + * match.c (debuglcf): Cosmetic fix. + (match_files): After recognizing nothrow in the file spec, + replace it by a string. A few places expect first(files) to be + a string. The skip directive must return whatever + return value it obtained from the nested match_files call, + and not substitute the current line number, so that the + caller can proceed past the correct number of lines that + were matched. Fixed obj_t * being passed to %s printf specifier + in debug printf. Collect directive must make progress even + if the nested spec makes no progress (returns successfully, + but with the original line number). + * txr.c (version): Bump. + * txr.1: Bump version and date. + * txr/tests/004/query-1.txr: New test case. + * tests/004/query-1.expected: Expected result for new test case. + +2009-10-17 Kaz Kylheku <kkylheku@gmail.com> + + Version 017 Bugfix in exception subtype definition (defex). @@ -62,6 +62,7 @@ tests: txr $(TESTS) tests/001/%: TXR_ARGS := tests/001/data tests/002/%: TXR_OPTS := -DTESTDIR=tests/002 +tests/004/%: TXR_ARGS := -a 123 -b -c %.ok: %.txr ./txr $(TXR_DBG_OPTS) $(TXR_OPTS) $^ $(TXR_ARGS) > $(@:.ok=.out) @@ -72,7 +72,7 @@ static void debuglcf(obj_t *line, const char *fmt, ...) if (opt_loglevel >= 2) { va_list vl; va_start (vl, fmt); - format(std_error, "~a: (~a:~a)", prog_string, spec_file_str, line, nao); + format(std_error, "~a: (~a:~a) ", prog_string, spec_file_str, line, nao); vcformat(std_error, fmt, vl); put_cchar(std_error, '\n'); va_end (vl); @@ -906,6 +906,8 @@ obj_t *match_files(obj_t *spec, obj_t *files, return nil; } + files = cons(name, cdr(files)); /* Get rid of cons and nothrow */ + if ((data = complex_snarf(fp, name)) != nil) data_lineno = 1; } @@ -938,14 +940,12 @@ repeat_spec_same_data: uw_block_begin(nil, result); while (dataline && (!max || reps++ < cmax)) { - cons_bind (new_bindings, success, - match_files(spec, files, bindings, - data, num(data_lineno))); + result = match_files(spec, files, bindings, + data, num(data_lineno)); - if (success) { + if (result) { debuglf(spec_linenum, "skip matched ~a:~a", first(files), num(data_lineno), nao); - result = cons(new_bindings, cons(data, num(data_lineno))); break; } @@ -1187,7 +1187,7 @@ repeat_spec_same_data: if (success) { debuglcf(spec_linenum, "collect matched %s:%ld", - first(files), data_lineno); + c_str(first(files)), data_lineno); for (iter = new_bindings; iter && iter != bindings; iter = cdr(iter)) @@ -1202,11 +1202,22 @@ repeat_spec_same_data: if (success) { if (consp(success)) { + cons_bind (new_data, new_line, success); + long new_lineno = c_num(new_line); + + bug_unless (new_lineno >= data_lineno); + + if (new_lineno == data_lineno) { + new_data = cdr(new_data); + new_lineno++; + } + debuglcf(spec_linenum, - "collect advancing from line d to %ld", - data_lineno, c_num(cdr(success))); - data = car(success); - data_lineno = c_num(cdr(success)); + "collect advancing from line %ld to %ld", + data_lineno, new_lineno); + + data = new_data; + data_lineno = new_lineno; } else { debuglf(spec_linenum, "collect consumed entire file", nao); data = nil; diff --git a/tests/004/query-1.expected b/tests/004/query-1.expected new file mode 100644 index 00000000..c07de878 --- /dev/null +++ b/tests/004/query-1.expected @@ -0,0 +1,3 @@ +option a was supplied, with argument 123 +option b was supplied +option c was supplied diff --git a/tests/004/query-1.txr b/tests/004/query-1.txr new file mode 100644 index 00000000..c8a9e226 --- /dev/null +++ b/tests/004/query-1.txr @@ -0,0 +1,67 @@ +#!./txr +@(next args) +@# +@# Define option_error exception, subtyped from error +@# +@(defex option_error error) +@# +@# Function for matching option that takes no argument +@# +@(define match_option (text opt_sym)) +@ (cases) +@ (skip) +@ text +@ (bind opt_sym "y") +@ (or) +@ (bind opt_sym "n") +@ (end) +@(end) +@# +@# Function for matching option that takes an argument +@# +@(define match_option_arg (text opt_sym arg_sym)) +@ (cases) +@ (skip) +@ text +@ arg_sym +@ (bind opt_sym "y") +@ (or) +@ (skip) +@ text +@ (throw option_error `@text requires arg`) +@ (or) +@ (bind opt_sym "n") +@ (end) +@(end) +@# +@# Main query +@# +@(try) +@ (maybe) +@ (match_option_arg "-a" opt_a opt_arg_a) +@ (or) +@ (match_option "-b" opt_b) +@ (or) +@ (match_option "-c" opt_c) +@ (end) +@ (maybe) +@ (bind opt_a "y") +@ (output) +option a was supplied, with argument @opt_arg_a +@ (end) +@ (or) +@ (bind opt_b "y") +@ (output) +option b was supplied +@ (end) +@ (or) +@ (bind opt_c "y") +@ (output) +option c was supplied +@ (end) +@ (end) +@(catch option_error (arg)) +@(output) +error: @arg +@(end) +@(end) @@ -21,7 +21,7 @@ .\"IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED .\"WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -.TH txr 1 2009-10-14 "txr v. 017" "Text Extraction Utility" +.TH txr 1 2009-10-17 "txr v. 018" "Text Extraction Utility" .SH NAME txr \- text extractor .SH SYNOPSIS @@ -39,7 +39,7 @@ #include "match.h" #include "txr.h" -const char *version = "017"; +const char *version = "018"; const char *progname = "txr"; const char *spec_file = "stdin"; obj_t *spec_file_str; |