[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9996b5b 31/60: Update full-csv-parser
From: |
Junpeng Qiu |
Subject: |
[elpa] master 9996b5b 31/60: Update full-csv-parser |
Date: |
Tue, 25 Oct 2016 17:45:14 +0000 (UTC) |
branch: master
commit 9996b5b50849ce77598075ae82f22be00bedbc67
Author: Junpeng Qiu <address@hidden>
Commit: Junpeng Qiu <address@hidden>
Update full-csv-parser
---
examples/full-csv-parser-tests.el | 51 +++++++++++++++++++++++++++++++++++++
examples/full-csv-parser.el | 16 ++++--------
examples/simple-csv-parser.el | 2 +-
3 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/examples/full-csv-parser-tests.el
b/examples/full-csv-parser-tests.el
new file mode 100644
index 0000000..ace150f
--- /dev/null
+++ b/examples/full-csv-parser-tests.el
@@ -0,0 +1,51 @@
+;;; full-csv-parser-tests.el --- Tests for full-csv-parser -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2016 Junpeng Qiu
+
+;; Author: Junpeng Qiu <address@hidden>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU 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 General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'full-csv-parser)
+
+(ert-deftest test-full-csv ()
+ (should
+ (equal
+ (parse-csv "\"a,1,s\",b,\r\nd,e,f")
+ '(("a,1,s" "b" "")
+ ("d" "e" "f"))))
+ (should
+ (equal
+ (parse-csv "\"e\"\",f")
+ (parsec-error-new-2 "\"" "`EOF'")))
+ (should
+ (equal
+ (parse-csv "\"a,1,\r\n")
+ (parsec-error-new-2 "\"" "`EOF'")))
+ (should
+ (equal
+ (parse-csv "\"a,1,\",b,\r\nd,,f")
+ '(("a,1," "b" "")
+ ("d" "" "f")))))
+
+(provide 'full-csv-parser-tests)
+;;; full-csv-parser-tests.el ends here
diff --git a/examples/full-csv-parser.el b/examples/full-csv-parser.el
index 9320373..8c76937 100644
--- a/examples/full-csv-parser.el
+++ b/examples/full-csv-parser.el
@@ -25,7 +25,7 @@
;;; Code:
(defun csv-file ()
- (parsec-ensure
+ (parsec-start
(parsec-return (parsec-endby (csv-line) (csv-eol))
(parsec-eob))))
@@ -33,12 +33,13 @@
(parsec-sepby (csv-cell) (parsec-ch ?,)))
(defun csv-cell ()
- (parsec-or (csv-quoted-cell) (parsec-many-as-string (parsec-re "[^,\n\r]"))))
+ (parsec-or (csv-quoted-cell) (parsec-many-as-string
+ (parsec-none-of ?, ?\r ?\n))))
(defun csv-quoted-cell ()
(parsec-and (parsec-ch ?\")
(parsec-return (parsec-many-as-string (csv-quoted-char))
- (parsec-ensure (parsec-ch ?\")))))
+ (parsec-ch ?\"))))
(defun csv-quoted-char ()
(parsec-or (parsec-re "[^\"]")
@@ -53,15 +54,8 @@
(parsec-eob)))
(defun parse-csv (input)
- (with-temp-buffer
- (insert input)
- (goto-char (point-min))
+ (parsec-with-input input
(csv-file)))
-(parse-csv "\"a,1,s\"s,b,\r\nd,e,f")
-(parse-csv "\"e\"\",f")
-(parse-csv "\"a,1,\r\n")
-(parse-csv "\"a,1,\"\",b,\r\nd,,f")
-
(provide 'full-csv-parser)
;;; full-csv-parser.el ends here
diff --git a/examples/simple-csv-parser.el b/examples/simple-csv-parser.el
index c2c55e8..2132ecd 100644
--- a/examples/simple-csv-parser.el
+++ b/examples/simple-csv-parser.el
@@ -41,7 +41,7 @@
(cons (s-csv-cell-content) (s-csv-remaining-cells)))
(defun s-csv-cell-content ()
- (parsec-many-as-string (parsec-re "[^,\n]")))
+ (parsec-many-as-string (parsec-none-of ?, ?\n)))
(defun s-csv-remaining-cells ()
(parsec-or (parsec-and (parsec-ch ?,) (s-csv-cells)) nil))
- [elpa] master updated (e479a3e -> dfb3af0), Junpeng Qiu, 2016/10/25
- [elpa] master d21bf7d 14/60: Remove unused code, Junpeng Qiu, 2016/10/25
- [elpa] master 108879f 11/60: Better propagate naming and implementation, Junpeng Qiu, 2016/10/25
- [elpa] master 5810eef 21/60: Remove parsec-continue, Junpeng Qiu, 2016/10/25
- [elpa] master 452ec1e 35/60: Update scheme parser, Junpeng Qiu, 2016/10/25
- [elpa] master 14b28a1 16/60: Add basic README, Junpeng Qiu, 2016/10/25
- [elpa] master 606fed1 10/60: Add simple JSON parser, Junpeng Qiu, 2016/10/25
- [elpa] master d8cd9d6 17/60: Better naming, Junpeng Qiu, 2016/10/25
- [elpa] master a5ca813 04/60: Full & simple parser, Junpeng Qiu, 2016/10/25
- [elpa] master 9996b5b 31/60: Update full-csv-parser,
Junpeng Qiu <=
- [elpa] master bdfcbde 23/60: Update library description, Junpeng Qiu, 2016/10/25
- [elpa] master 2e8c52b 40/60: Make sure parsec-not-followed-by consumes no input, Junpeng Qiu, 2016/10/25
- [elpa] master fb26929 34/60: Fix parsec-make-alternatives, Junpeng Qiu, 2016/10/25
- [elpa] master 31388e6 52/60: Add -s aliases, Junpeng Qiu, 2016/10/25
- [elpa] master 34521c6 53/60: Update README about *-s functions, Junpeng Qiu, 2016/10/25
- [elpa] master 8f0c266 58/60: Add doc for parsec-peek(-p), Junpeng Qiu, 2016/10/25
- [elpa] master ffd42de 45/60: Use simple-csv-parser.el as a demo, Junpeng Qiu, 2016/10/25
- [elpa] master bf49fb6 38/60: Upate README, Junpeng Qiu, 2016/10/25
- [elpa] master 966ca9e 43/60: Add comments to parsec.el, Junpeng Qiu, 2016/10/25
- [elpa] master c61a38c 22/60: Add convenient newline methods, Junpeng Qiu, 2016/10/25