summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-04 04:21:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-04 04:21:57 -0700
commit20758a37854c852c5a6574ced48bb0aca9417132 (patch)
treef30bf9b7aee1b45b689103f3609f1ec44f9f6809
parentb74633f86d69cf1aabebe0b976d695b7a61bddc6 (diff)
downloadtxr-20758a37854c852c5a6574ced48bb0aca9417132.tar.gz
txr-20758a37854c852c5a6574ced48bb0aca9417132.tar.bz2
txr-20758a37854c852c5a6574ced48bb0aca9417132.zip
New awk clauses :set and :set-file.
* share/txr/stdlib/awk.tl (sys:awk-expander): Recognize :set and :set-file cases. * txr.1: Documented :set and :set-file, replacing some :begin uses with :set in the examples.
-rw-r--r--share/txr/stdlib/awk.tl2
-rw-r--r--txr.123
2 files changed, 22 insertions, 3 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 47028802..84688768 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -190,8 +190,10 @@
(set awc.name (car actions)))
(:let (push actions awc.lets))
(:begin (push actions awc.begin-actions))
+ (:set (push ^((set ,*actions)) awc.begin-actions))
(:end (push actions awc.end-actions))
(:begin-file (push actions awc.begin-file-actions))
+ (:set-file (push ^((set ,*actions)) awc.begin-actions))
(:end-file (push actions awc.end-file-actions))
(t (push (if actions
cl
diff --git a/txr.1 b/txr.1
index 51f35bc8..e215ee16 100644
--- a/txr.1
+++ b/txr.1
@@ -38559,8 +38559,10 @@ with special semantics:
.codn :inputs ,
.codn :output ,
.codn :begin ,
+.codn :set ,
.codn :end ,
-.code :begin-file
+.codn :begin-file ,
+.code :set-file
and
.codn :end-file .
These clause types are explained below.
@@ -38664,6 +38666,7 @@ and
clauses.
In
.codn :begin ,
+.codn :set ,
.codn :end ,
and ordinary clauses, it will be shadowed by the
.code awk
@@ -38749,6 +38752,13 @@ Each
.code form
is evaluated. These forms have in their scope the awk local variables
and macros.
+.meIP (:set >> { place << new-value }*)
+The
+.code :set
+clause provides a shorthand which allows the frequently occurring pattern
+.code "(:begin (set ...))"
+to be condensed to
+.codn "(:set ...)" .
.meIP (:end << form *)
All
.code :end
@@ -38813,6 +38823,13 @@ forms are specified, then before the first input is processed,
clauses are processed first, then the
.code :begin-file
clauses.
+.meIP (:set-file >> { place << new-value }*)
+The
+.code :set-file
+clause is a shorthand which translates
+.code "(:set-file ...)"
+to
+.codn "(:begin-file (set ...))" .
.meIP (:end-file << form *)
All
.code :end-file
@@ -39899,7 +39916,7 @@ Same as 11, but with field separation consisting of a
comma, or spaces and tabs, or both in sequence:
.cblk
- (awk (:begin (set fs #/,[ \et]*|[ \et]+/))
+ (awk (:set fs #/,[ \et]*|[ \et]+/)
(t (prn [f 1] [f 0])))
.cble
.IP 13.
@@ -39971,7 +39988,7 @@ environment variable, one per line:
.cblk
;; Process variable as if it were a file:
(awk (:inputs (make-string-input-stream (getenv "PATH")))
- (:begin (set fs ":"))
+ (:set fs ":")
(t (tprint f)))
;; Just get, split and print; awk macro is irrelevant