diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | match.c | 18 | ||||
-rw-r--r-- | txr.1 | 22 |
3 files changed, 47 insertions, 2 deletions
@@ -1,3 +1,12 @@ +2011-09-22 Kaz Kylheku <kaz@kylheku.com> + + Useful second argument in skip directive for skipping + a minimum number of lines. + + * match.c (match_files): New behavior in skip_s case. + + * txr.1: Documented. + 2010-10-05 Kaz Kylheku <kkylheku@gmail.com> Version 035 @@ -924,8 +924,9 @@ repeat_spec_same_data: if (sym == skip_s) { val max = first(rest(first_spec)); + val min = second(rest(first_spec)); cnum cmax = nump(max) ? c_num(max) : 0; - cnum reps = 0; + cnum cmin = nump(min) ? c_num(min) : 0; if (rest(specline)) sem_error(spec_linenum, @@ -935,9 +936,22 @@ repeat_spec_same_data: break; { + cnum reps_max = 0, reps_min = 0; + cnum old_lineno = data_lineno; uw_block_begin(nil, result); - while (data && (!max || reps++ < cmax)) { + while (data && min && reps_min++ < cmin) { + data = rest(data); + data_lineno++; + } + + if (min) { + debuglf(spec_linenum, lit("skipped ~a lines to ~a:~a"), + num(data_lineno - old_lineno), first(files), + num(data_lineno), nao); + } + + while (data && (!max || reps_max++ < cmax)) { result = match_files(spec, files, bindings, data, num(data_lineno)); @@ -1102,6 +1102,28 @@ be written instead: end @BEG_SYMBOL @(end) +If the symbol nil is used in place of a number, it means to scan +an unlimited range of lines; thus, @(skip nil) is equivalent to @(skip). + +There may be a second numeric argument. This specifies a minimum +number of lines to skip before looking for a match. For instance, +skip 15 lines and then search indefinitely for "begin ...": + + @(skip nil 15) + begin @BEG_SYMBOL + +The two arguments may be used together. For instance, the following +matches if, and only if, the 15th line of input starts with "begin ": + + @(skip 1 15) + begin @BEG_SYMBOL + +Essentially, @(skip 1 <n>) means "hard skip by <n>" lines, then +match the query without scanning. @(skip 1 0) is the same as @(skip 1), which +is a noop, because it means: "the remainder of the query must match starting on +the very next line", or, more briefly, "skip exactly zero lines", which is the +behavior if the skip directive is omitted altogether. + .SS The Trailer Directive The trailer directive introduces a trailing portion of a query or subquery |