From 572f6a3dbe1643ece48a2208b809f5d7143b6e05 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 14 Jan 2018 15:29:44 +0100 Subject: [PATCH] Fix CSV separator parsing. The previous patch introduced parser conflicts and we couldn't parse some expressions any more, such as the following: fields escaped by '\', It's now possible to represent single quote as either '''', '\'', or '0x27' and we still can parse '\' as being a single backslash character. See #705. --- src/parsers/command-csv.lisp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/parsers/command-csv.lisp b/src/parsers/command-csv.lisp index 2a1657f..c141f29 100644 --- a/src/parsers/command-csv.lisp +++ b/src/parsers/command-csv.lisp @@ -34,14 +34,22 @@ (bind (((_ digits) hex)) (code-char (parse-integer (text digits) :radix 16))))) -(defrule tab (and #\\ #\t) (:constant #\Tab)) +(defrule tab-separator (and #\' #\\ #\t #\') (:constant #\Tab)) +(defrule backslash-separator (and #\' #\\ #\') (:constant #\\)) -(defrule single-quote (and #\\ #\') (:constant #\')) +(defrule single-quote-separator (or (and #\' #\' #\' #\') + (and #\' #\\ #\' #\')) + (:constant #\')) -(defrule separator (and #\' (or hex-char-code tab single-quote character) #\') +(defrule other-char-separator (and #\' (or hex-char-code character) #\') (:lambda (sep) (bind (((_ char _) sep)) char))) +(defrule separator (or single-quote-separator + backslash-separator + tab-separator + other-char-separator)) + ;; ;; Main CSV options (WITH ... in the command grammar) ;;