diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-10-04 22:05:52 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-10-04 22:05:52 -0700 |
commit | 0da50195d575904acf55e363117ad98db242923b (patch) | |
tree | 3975bed1e1ed8c4275a0df5b7f97757403b36e07 /tests | |
parent | eb257d57926b2e5d2b965984af136ba0beabbb10 (diff) | |
download | txr-0da50195d575904acf55e363117ad98db242923b.tar.gz txr-0da50195d575904acf55e363117ad98db242923b.tar.bz2 txr-0da50195d575904acf55e363117ad98db242923b.zip |
awk: :fields specifies conversions.
* stdlib/awk.tl (sys:awk-compile-time): Slot field-names renamed to
field-name-conv.
(sys:awk-expander): Parse the new syntax which allows (sym fn)
pairs with optional fn, creating a list of normalized items
in the field-name-conv slot of the compile-time structure.
(sys:awk-symac-let): Adjust the code to the pair representation in
field-name-conv.
(sys:awk-field-name-code): New function for generating the
field conversion code.
(awk): Now that we have two optional pieces of code to wrap around
p-actions form, we factor that out of the awk-lambda, to a series
of conditional assignments. Here we handle the generation of the
field conversionns.
* conv.tl (sys:conv-expand-sym): New macro, used in
sys:awk-field-name-code and sys:conv-let.
(sys:conv-let): Simplify with sys:conv-expand-sym. Drop optional
argument from i; it connects with no documented feature, and is
not usable from fconv.
* tests/015/awk-fields.tl: New tests.
* txr.1: Updated, including cruft in fconv documentation.
Change-Id: Ie42819f58af039fdbcdb1ae365c89dc1add55c93
Diffstat (limited to 'tests')
-rw-r--r-- | tests/015/awk-fields.tl | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/015/awk-fields.tl b/tests/015/awk-fields.tl index 7f27e9e4..7bb2f599 100644 --- a/tests/015/awk-fields.tl +++ b/tests/015/awk-fields.tl @@ -6,7 +6,10 @@ (awk (:fields nil) (:begin (return-from awk))) :error (awk (:fields - -) (:begin (return-from awk))) nil (awk (:fields a - - b) (:begin (return-from awk))) nil - (awk (:fields a - - a) (:begin (return-from awk))) :error + (awk (:fields (a foo) - - (a bar)) (:begin (return-from awk))) :error + (awk (:fields (a foo) - - (b bar)) (:begin (return-from awk))) nil + (awk (:fields (a foo) (-) - (b bar)) (:begin (return-from awk))) :error + (awk (:fields (a foo) (- i) - (b bar)) (:begin (return-from awk))) :error (awk (:fields a) (:fields b) (:begin (return-from awk))) :error) (test @@ -16,3 +19,19 @@ (:fields h n - c) (t (add h n c)))) ("How" "now" "cow")) + +(test + (build + (awk + (:inputs '("1 x 2" "a x 1" "4 x b")) + (:fields (foo iz) - (bar iz)) + (t (add (+ foo bar))))) + (3 1 4)) + +(test + (build + (awk + (:inputs '("1")) + (:fields (a iz) - (c iz)) + (t (add (+ a c) nf)))) + (1 3)) |