Improve parsing of list separating commas wrt to whitespacing.

This commit is contained in:
Dimitri Fontaine 2013-11-23 21:49:08 +01:00
parent c482015248
commit ea4e74e545
2 changed files with 45 additions and 45 deletions

View File

@ -500,10 +500,13 @@
option-foreign-keys option-foreign-keys
option-identifiers-case)) option-identifiers-case))
(defrule another-mysql-option (and #\, ignore-whitespace mysql-option) (defrule comma (and ignore-whitespace #\, ignore-whitespace)
(:constant :comma))
(defrule another-mysql-option (and comma mysql-option)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws option) source (destructuring-bind (comma option) source
(declare (ignore comma ws)) (declare (ignore comma))
option))) option)))
(defrule mysql-option-list (and mysql-option (* another-mysql-option)) (defrule mysql-option-list (and mysql-option (* another-mysql-option))
@ -535,10 +538,10 @@
(declare (ignore es)) (declare (ignore es))
(cons name value)))) (cons name value))))
(defrule another-generic-option (and #\, ignore-whitespace generic-option) (defrule another-generic-option (and comma generic-option)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws option) source (destructuring-bind (comma option) source
(declare (ignore comma ws)) (declare (ignore comma))
option))) option)))
(defrule generic-option-list (and generic-option (* another-generic-option)) (defrule generic-option-list (and generic-option (* another-generic-option))
@ -571,10 +574,10 @@
(declare (ignore open close)) (declare (ignore open close))
(text quoted)))) (text quoted))))
(defrule another-dollar-quoted (and ignore-whitespace #\, dollar-quoted) (defrule another-dollar-quoted (and comma dollar-quoted)
(:lambda (source) (:lambda (source)
(destructuring-bind (ws comma quoted) source (destructuring-bind (comma quoted) source
(declare (ignore ws comma)) (declare (ignore comma))
quoted))) quoted)))
(defrule dollar-quoted-list (and dollar-quoted (* another-dollar-quoted)) (defrule dollar-quoted-list (and dollar-quoted (* another-dollar-quoted))
@ -733,10 +736,10 @@
:target (fix-target-type source target) :target (fix-target-type source target)
:using function)))) :using function))))
(defrule another-cast-rule (and #\, ignore-whitespace cast-rule) (defrule another-cast-rule (and comma cast-rule)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws rule) source (destructuring-bind (comma rule) source
(declare (ignore comma ws)) (declare (ignore comma))
rule))) rule)))
(defrule cast-rule-list (and cast-rule (* another-cast-rule)) (defrule cast-rule-list (and cast-rule (* another-cast-rule))
@ -768,10 +771,10 @@
(defrule view-definition (and view-name (? view-sql)) (defrule view-definition (and view-name (? view-sql))
(:destructure (name sql) (cons name sql))) (:destructure (name sql) (cons name sql)))
(defrule another-view-definition (and #\, ignore-whitespace view-definition) (defrule another-view-definition (and comma view-definition)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws view) source (destructuring-bind (comma view) source
(declare (ignore comma ws)) (declare (ignore comma))
view))) view)))
(defrule views-list (and view-definition (* another-view-definition)) (defrule views-list (and view-definition (* another-view-definition))
@ -788,13 +791,10 @@
;;; ;;;
(defrule namestring-or-regex (or quoted-namestring quoted-regex)) (defrule namestring-or-regex (or quoted-namestring quoted-regex))
(defrule another-namestring-or-regex (and ignore-whitespace (defrule another-namestring-or-regex (and comma namestring-or-regex)
#\,
ignore-whitespace
namestring-or-regex)
(:lambda (source) (:lambda (source)
(destructuring-bind (w1 comma w2 re) source (destructuring-bind (comma re) source
(declare (ignore w1 comma w2)) (declare (ignore comma))
re))) re)))
(defrule filter-list (and namestring-or-regex (* another-namestring-or-regex)) (defrule filter-list (and namestring-or-regex (* another-namestring-or-regex))
@ -910,10 +910,10 @@ load database
option-create-indexes option-create-indexes
option-reset-sequences)) option-reset-sequences))
(defrule another-sqlite-option (and #\, ignore-whitespace sqlite-option) (defrule another-sqlite-option (and comma sqlite-option)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws option) source (destructuring-bind (comma option) source
(declare (ignore comma ws)) (declare (ignore comma))
option))) option)))
(defrule sqlite-option-list (and sqlite-option (* another-sqlite-option)) (defrule sqlite-option-list (and sqlite-option (* another-sqlite-option))
@ -1147,10 +1147,10 @@ load database
(defrule dbf-option (or option-truncate option-create-table option-table-name)) (defrule dbf-option (or option-truncate option-create-table option-table-name))
(defrule another-dbf-option (and #\, ignore-whitespace dbf-option) (defrule another-dbf-option (and comma dbf-option)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws option) source (destructuring-bind (comma option) source
(declare (ignore comma ws)) (declare (ignore comma))
option))) option)))
(defrule dbf-option-list (and dbf-option (* another-dbf-option)) (defrule dbf-option-list (and dbf-option (* another-dbf-option))
@ -1314,10 +1314,10 @@ load database
option-trim-unquoted-blanks option-trim-unquoted-blanks
option-keep-unquoted-blanks)) option-keep-unquoted-blanks))
(defrule another-csv-option (and #\, ignore-whitespace csv-option) (defrule another-csv-option (and comma csv-option)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws option) source (destructuring-bind (comma option) source
(declare (ignore comma ws)) (declare (ignore comma))
option))) option)))
(defrule csv-option-list (and csv-option (* another-csv-option)) (defrule csv-option-list (and csv-option (* another-csv-option))
@ -1380,10 +1380,10 @@ load database
(:destructure (name opts) (:destructure (name opts)
`(,name ,@opts))) `(,name ,@opts)))
(defrule another-csv-source-field (and #\, ignore-whitespace csv-source-field) (defrule another-csv-source-field (and comma csv-source-field)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws field) source (destructuring-bind (comma field) source
(declare (ignore comma ws)) (declare (ignore comma))
field))) field)))
(defrule csv-source-fields (and csv-source-field (* another-csv-source-field)) (defrule csv-source-fields (and csv-source-field (* another-csv-source-field))
@ -1467,10 +1467,10 @@ load database
(list name type expr)) (list name type expr))
(list name nil nil))))) (list name nil nil)))))
(defrule another-csv-target-column (and #\, ignore-whitespace csv-target-column) (defrule another-csv-target-column (and comma csv-target-column)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws col) source (destructuring-bind (comma col) source
(declare (ignore comma ws)) (declare (ignore comma))
col))) col)))
(defrule csv-target-columns (and csv-target-column (defrule csv-target-columns (and csv-target-column
@ -1620,10 +1620,10 @@ load database
(:destructure (name start len opts) (:destructure (name start len opts)
`(,name :start ,start :length ,len ,@opts))) `(,name :start ,start :length ,len ,@opts)))
(defrule another-fixed-source-field (and #\, ignore-whitespace fixed-source-field) (defrule another-fixed-source-field (and comma fixed-source-field)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws field) source (destructuring-bind (comma field) source
(declare (ignore comma ws)) (declare (ignore comma))
field))) field)))
(defrule fixed-source-fields (and fixed-source-field (* another-fixed-source-field)) (defrule fixed-source-fields (and fixed-source-field (* another-fixed-source-field))
@ -1640,10 +1640,10 @@ load database
(defrule fixed-option (or option-truncate (defrule fixed-option (or option-truncate
option-skip-header)) option-skip-header))
(defrule another-fixed-option (and #\, ignore-whitespace fixed-option) (defrule another-fixed-option (and comma fixed-option)
(:lambda (source) (:lambda (source)
(destructuring-bind (comma ws option) source (destructuring-bind (comma option) source
(declare (ignore comma ws)) (declare (ignore comma))
option))) option)))
(defrule fixed-option-list (and fixed-option (* another-fixed-option)) (defrule fixed-option-list (and fixed-option (* another-fixed-option))

View File

@ -18,9 +18,9 @@ LOAD CSV
(d, b, x, y) (d, b, x, y)
INTO postgresql:///pgloader?udc INTO postgresql:///pgloader?udc
( (
b, b
c text using "constant value", , c text using "constant value"
d , d
) )
WITH fields optionally enclosed by '"', WITH fields optionally enclosed by '"',