From 0da50195d575904acf55e363117ad98db242923b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 4 Oct 2021 22:05:52 -0700 Subject: 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 --- tests/015/awk-fields.tl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/015/awk-fields.tl') 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)) -- cgit v1.2.3