emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]