From ac87ac1294de72a6bbc84b0eb68a605d17058796 Mon Sep 17 00:00:00 2001 From: Brady McDonough Date: Sun, 7 Mar 2021 18:49:52 -0700 Subject: [PATCH] fixed empty final cells being ignored --- Makefile | 2 +- csv/csv.scm | 8 ++++++-- csv/transform.scm | 46 ---------------------------------------------- 3 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 csv/transform.scm diff --git a/Makefile b/Makefile index 1b8cfcf..86e7925 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ TARGET := $(shell guile -c "(display (%site-dir))") CCACHE := $(shell guile -c "(display(%site-ccache-dir))") -OBJ := csv.go transform.go +OBJ := csv.go .PHONY: all clean install uninstall all: $(OBJ) diff --git a/csv/csv.scm b/csv/csv.scm index f59dbb2..a1cfd8d 100644 --- a/csv/csv.scm +++ b/csv/csv.scm @@ -37,13 +37,17 @@ (define (finish-cell b seed) (have-cell (list->string (reverse b)) seed)) (define (next-cell b seed) - (state-init (!) (finish-cell b seed))) + (state-finish-cell (!) (finish-cell b seed))) (define (state-init c seed) (cond ((eqv? c delimiter) (state-init (!) (have-cell "" seed))) ((eqv? c #\") (state-string (!) '() seed)) - ((eqv? c #\newline) seed) + ((eqv? c #\newline) (have-cell "" seed)) ((eof-object? c) seed) (else (state-any c '() seed)))) + (define (state-finish-cell c seed) + (cond ((eqv? c #\newline) seed) + ((eof-object? c) seed) + (else (state-init c seed)))) (define (state-string c b seed) (cond ((eqv? c #\") (state-string-quote (!) b seed)) ((eof-object? c) (error "Open double-quoted string" (list->string (reverse b)))) diff --git a/csv/transform.scm b/csv/transform.scm deleted file mode 100644 index 500fdb0..0000000 --- a/csv/transform.scm +++ /dev/null @@ -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)))))))))