From dd3884648c375a775ed1e777e5f8f58db5d226d7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 19 May 2017 20:36:45 -0700 Subject: awk: new feature: again operator. * share/txr/stdlib/awk.tl (sys:awk-state loop): Wrap a loop around around the two forms that split the record into fields and dispatch the main rule function. The loop repeats if the named block returns :awk-again. (sys:awk-mac-let): New local macro (again) which bails out of the :awk-rec block just like (next) does, but specifies :awk-again as the return value. * txr.1: Documented. --- share/txr/stdlib/awk.tl | 6 +++--- txr.1 | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index 5b19e706..b0f54aaf 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -172,9 +172,8 @@ (set aws.rec rec aws.orig-rec rec) (inc aws.rec-num) (inc aws.file-rec-num) - aws.(rec-to-f) - (block :awk-rec - [func aws])) + (while* (eq :awk-again (block :awk-rec [func aws])) + aws.(rec-to-f))) (when end-file-func [end-file-func aws]))))))) @@ -294,6 +293,7 @@ (ofs (qref ,aws-sym ofs)) (ors (qref ,aws-sym ors))) (macrolet ((next () '(return-from :awk-rec)) + (again () '(return-from :awk-rec :awk-again)) (next-file () '(return-from :awk-file)) (sys:rng (form from-expr to-expr :env e) (let ((style (car form)) diff --git a/txr.1 b/txr.1 index cff7cd87..6ac4422a 100644 --- a/txr.1 +++ b/txr.1 @@ -45022,6 +45022,31 @@ record, .code awk terminates. +.coNP Macro @ again +.synb +.mets (again) +.syne +.desc +The awk macro +.code again +may be invoked in a condition-pattern clause. It terminates the +processing of that clause, and all subsequent clauses. +Then, the current value of the record, namely the datum stored +in the Awk variable +.codn rec , +is delimited into fields, and all of the condition-pattern clauses +are processed again. + +No other state is modified. In particular, the record number +.code nr +and the +.code orec +variable holding the original record both retain their current values. + +Note: this is an original feature in the \*(TL +.code awk +macro, which has no counterpart in POSIX or GNU Awk. + .coNP Macro @ next-file .synb .mets (next-file) -- cgit v1.2.3