diff --git a/pgloader.1.md b/pgloader.1.md index 708ceab..b56ec89 100644 --- a/pgloader.1.md +++ b/pgloader.1.md @@ -88,8 +88,30 @@ http://www.postgresql.org/docs/9.3/static/libpq-connect.html#LIBPQ-CONNSTRING. postgresql://[user[:password]@][netloc][:port][/dbname][?schema.table] -The connection string in pgloader only accepts a single optionnal parameter -which should be a possibly qualified table name. +Where: + + - *user* + + Can contain any character, including colon (`:`) which must then be + doubled (`::`). + + - *password* + + Can contain any character, including that at sign (`@`) which must then + be doubled (`@@`). To leave the password empty, when the *user* name + ends with at at sign, you then have to use the syntax user:@. + + - *netloc* + + Can be either a hostname in dotted notation, or an ipv4. + + - *dbname* + + Should be a proper identifier (letter followed by a mix of letters, + digits and the punctuation signs comma (`,`), dash (`-`) and underscore + (`_`). + + - The only optionnal parameter should be a possibly qualified table name. ## LOAD CSV diff --git a/src/parser.lisp b/src/parser.lisp index e3da182..77c4d12 100644 --- a/src/parser.lisp +++ b/src/parser.lisp @@ -209,8 +209,13 @@ (list :port (if (null digits) digits (parse-integer port))))) -(defrule dsn-user-password (and namestring - (? (and ":" (? namestring))) +(defrule doubled-at-sign (and "@@") (:constant "@")) +(defrule doubled-colon (and "::") (:constant ":")) +(defrule password (+ (or (not "@") doubled-at-sign)) (:text t)) +(defrule username (+ (or (not ":") doubled-colon)) (:text t)) + +(defrule dsn-user-password (and username + (? (and ":" (? password))) "@") (:lambda (args) (destructuring-bind (username &optional password) @@ -218,7 +223,17 @@ ;; password looks like '(":" "password") (list :user username :password (cadr password))))) -(defrule hostname (and namestring (? (and "." hostname))) +(defun hexdigit-char-p (character) + (member character #. (quote (coerce "0123456789abcdefABCDEF" 'list)))) + +(defrule ipv4-part (and (digit-char-p character) + (? (digit-char-p character)) + (? (digit-char-p character)))) + +(defrule ipv4 (and ipv4-part "." ipv4-part "." ipv4-part "." ipv4-part) + (:text t)) + +(defrule hostname (or ipv4 (and namestring (? (and "." hostname)))) (:text t)) (defrule dsn-hostname (and hostname (? dsn-port)) @@ -1030,9 +1045,6 @@ load database fields escaped by '\"', fields terminated by '\t'; |# -(defun hexdigit-char-p (character) - (member character #. (quote (coerce "0123456789abcdefABCDEF" 'list)))) - (defrule hex-char-code (and "0x" (+ (hexdigit-char-p character))) (:lambda (hex) (destructuring-bind (prefix digits) hex