parent
80b0ae61b9
commit
ac87ac1294
@ -1,46 +0,0 @@
|
|||||||
;; guile-csv transform
|
|
||||||
;; Copyright (C) 2021
|
|
||||||
;; Brady McDonough
|
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU Lesser General Public License as
|
|
||||||
;; published by the Free Software Foundation; either version 3 of the
|
|
||||||
;; License, or (at your option) any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful, but
|
|
||||||
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
;; Lesser General Public License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU Lesser General Public
|
|
||||||
;; License along with this program; if not, contact:
|
|
||||||
;;
|
|
||||||
;; Free Software Foundation, Inc. Voice: +1-617-542-5942
|
|
||||||
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
||||||
;; Boston, MA 02110-1301, USA gnu@gnu.org
|
|
||||||
|
|
||||||
(define-module (csv transform)
|
|
||||||
#:use-module (ice-9 receive)
|
|
||||||
#:use-module (sxml transform)
|
|
||||||
#:export (bubble-term)
|
|
||||||
#:re-export (pre-post-order))
|
|
||||||
|
|
||||||
(define (key-contains-defer str)
|
|
||||||
(lambda ($pair) (string-contains (symbol->string (car $pair)) str)))
|
|
||||||
|
|
||||||
;; Generates a handler for pre-post-order.
|
|
||||||
;; EXAMPLE USAGE:
|
|
||||||
;; (pre-post-order $tree `(,(bubble-term rec "key-name")
|
|
||||||
;; (*default* . ,(lambda x x))))
|
|
||||||
;; This will generate a rule which travels in *preorder* to each record named
|
|
||||||
;;'rec' and replace the rec symbol with the pair keyed as "key-name". The rest
|
|
||||||
;;of the record will be a quoted list.
|
|
||||||
(define-syntax bubble-term
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ record-sym $str)
|
|
||||||
`(record-sym *preorder* .
|
|
||||||
,(lambda $record
|
|
||||||
(let* (($lst (cadr $record)))
|
|
||||||
(receive (head rest)
|
|
||||||
(partition (key-contains-defer $str) $lst)
|
|
||||||
(cons head `(',rest)))))))))
|
|
||||||
Loading…
Reference in new issue