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.
This commit is contained in:
Dimitri Fontaine 2018-01-14 15:29:44 +01:00
parent bb6c3d0a32
commit 572f6a3dbe

View File

@ -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)
;;