From 1b8e26d7e59d9b76ee88f9135470cb3f11d399cb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 25 Sep 2016 08:49:04 -0700 Subject: awk macro: support paragraph mode. * share/txr/stdlib/awk.tl (sys:awk-state loop): If the rs variable is nil, provide a record reader which reads paragraphs, like under Awk's paragraph mode when RS is blank. This does not support the requirement that newline is always a field separator, regardless of the value of FS. * txr.1: Documented paragraph mode. --- txr.1 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 00822132..3293ef81 100644 --- a/txr.1 +++ b/txr.1 @@ -38559,6 +38559,14 @@ is .strn "\en" : the newline character. This means that, by default, records are lines. +If +.code rs +is changed to the value +.codn nil , +then record separation operates in +.IR "paragraph mode" , +which is described below. + If a match for the record separator occurs at the end of the stream, it is not considered to delimit an empty record, but acts as the terminator for the previous record. @@ -38569,6 +38577,33 @@ it has no effect on the most recently scanned and delimited record which is still current, or previous records. The new value applies to the next, not yet read record. +In paragraph mode, records are separated by a newline character followed by one +or more blank lines (empty lines or lines containing only a mixture of +tabs and spaces). This means that, effectively, the record-separating +sequences match the regular expression +.codn "/\en[ \en\et]*\en/" . +There is a difference between paragraph mode and simply using the above +regular expression as +.codn rs . +The difference is that if the first record which is read upon entering +paragraph mode is empty (because the input begins with a match for the +separator regex), then that record is thrown away, and the next record +is read. + +Note that the POSIX Awk paragraph mode (which occurs when +.code RS +is blank) there is an additional difference: regardless of the value +of the field separator +.codn FS , +newline characters separate fields. This behavior is not implemented +in the +.code awk +macro. Since newlines are included as separators in under the default field +separation, the behaviors match in that case. Code using a custom +.code fs +must explicitly include a match for newline to obtain that as a field +separator. + .coNP Variable @ krs .desc The awk variable -- cgit v1.2.3