summaryrefslogtreecommitdiffstats
path: root/stdlib/conv.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-10-04 22:05:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-10-04 22:05:52 -0700
commit0da50195d575904acf55e363117ad98db242923b (patch)
tree3975bed1e1ed8c4275a0df5b7f97757403b36e07 /stdlib/conv.tl
parenteb257d57926b2e5d2b965984af136ba0beabbb10 (diff)
downloadtxr-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 'stdlib/conv.tl')
-rw-r--r--stdlib/conv.tl46
1 files changed, 22 insertions, 24 deletions
diff --git a/stdlib/conv.tl b/stdlib/conv.tl
index f2f5bd4d..ef1088cc 100644
--- a/stdlib/conv.tl
+++ b/stdlib/conv.tl
@@ -24,31 +24,29 @@
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
;; POSSIBILITY OF SUCH DAMAGE.
+
+
+(defmacro sys:conv-expand-sym (sym arg-expr)
+ (caseq sym
+ (usr:i ^(toint ,arg-expr))
+ (usr:o ^(toint ,arg-expr 8))
+ (usr:x ^(toint ,arg-expr 16))
+ (usr:b ^(toint ,arg-expr 2))
+ (usr:c ^(toint ,arg-expr #\c))
+ (usr:r ^(tofloat ,arg-expr))
+ (usr:iz ^(tointz ,arg-expr))
+ (usr:oz ^(tointz ,arg-expr 8))
+ (usr:xz ^(tointz ,arg-expr 16))
+ (usr:bz ^(tointz ,arg-expr 2))
+ (usr:cz ^(tointz ,arg-expr #\c))
+ (usr:rz ^(tofloatz ,arg-expr))
+ (t ^(,sym ,arg-expr))))
+
(defun sys:conv-let (. body)
- ^(flet ((usr:i (arg : radix)
- (toint arg radix))
- (usr:o (arg)
- (toint arg 8))
- (usr:x (arg)
- (toint arg 16))
- (usr:b (arg)
- (toint arg 2))
- (usr:c (arg)
- (toint arg #\c))
- (usr:r (arg)
- (tofloat arg))
- (usr:iz (arg : radix)
- (tointz arg radix))
- (usr:oz (arg)
- (tointz arg 8))
- (usr:xz (arg)
- (tointz arg 16))
- (usr:bz (arg)
- (tointz arg 2))
- (usr:cz (arg)
- (tointz arg #\c))
- (usr:rz (arg)
- (tofloatz arg)))
+ ^(flet ,(collect-each ((sym '(usr:i usr:o usr:x usr:b usr:c
+ usr:r usr:iz usr:oz usr:xz
+ usr:bz usr:cz usr:rz)))
+ ^(,sym (arg) (sys:conv-expand-sym ,sym arg)))
,*body))
(defun sys:do-conv (lfl mfl tfl nm list)