diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-19 20:36:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-19 20:36:45 -0700 |
commit | dd3884648c375a775ed1e777e5f8f58db5d226d7 (patch) | |
tree | 69efa656bdbc60507ecd6be5fd9f1e98fe884bcb | |
parent | fe4c305ba334956e70de9bbbb0292fac7404338a (diff) | |
download | txr-dd3884648c375a775ed1e777e5f8f58db5d226d7.tar.gz txr-dd3884648c375a775ed1e777e5f8f58db5d226d7.tar.bz2 txr-dd3884648c375a775ed1e777e5f8f58db5d226d7.zip |
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.
-rw-r--r-- | share/txr/stdlib/awk.tl | 6 | ||||
-rw-r--r-- | 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)) @@ -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) |