summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-25 08:49:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-25 08:49:04 -0700
commit1b8e26d7e59d9b76ee88f9135470cb3f11d399cb (patch)
tree6bb570fffbb954fc6751aeb8ebfdb3e7f7c87e0f /share
parente4ad31de61b548238cb53b6a572dc7f16d93d78f (diff)
downloadtxr-1b8e26d7e59d9b76ee88f9135470cb3f11d399cb.tar.gz
txr-1b8e26d7e59d9b76ee88f9135470cb3f11d399cb.tar.bz2
txr-1b8e26d7e59d9b76ee88f9135470cb3f11d399cb.zip
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.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/awk.tl31
1 files changed, 22 insertions, 9 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 9ae7c569..3efd8cc6 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -93,15 +93,28 @@
(t
(set noted-rs aws.rs noted-krs aws.krs)
(set cached-rr
- (if (and (equal aws.rs "\n")
- (not aws.krs))
- (lambda () (get-line stin))
- (let ((rin (record-adapter (if (regexp aws.rs)
- aws.rs
- (regex-compile aws.rs))
- stin
- aws.krs)))
- (lambda () (get-line rin)))))))))
+ (cond
+ ((and (equal aws.rs "\n") (not aws.krs))
+ (lambda () (get-line stin)))
+ ((null aws.rs)
+ (let ((rin (record-adapter #/\n[ \n\t]*\n/))
+ (flag t))
+ (lambda ()
+ (let ((r (get-line rin)))
+ (cond
+ (flag
+ (set flag nil)
+ (if (equal r "")
+ (get-line rin)
+ r))
+ (t r))))))
+ (t
+ (let ((rin (record-adapter (if (regexp aws.rs)
+ aws.rs
+ (regex-compile aws.rs))
+ stin
+ aws.krs)))
+ (lambda () (get-line rin))))))))))
(set aws.file-rec-num 0)
(unwind-protect
(whilet ((rr (get-rec-reader stin))