From ehuelsmann at common-lisp.net Mon Feb 11 22:05:58 2008 From: ehuelsmann at common-lisp.net (ehuelsmann at common-lisp.net) Date: Mon, 11 Feb 2008 17:05:58 -0500 (EST) Subject: [py-configparser-cvs] r16 - trunk Message-ID: <20080211220558.D33435D086@common-lisp.net> Author: ehuelsmann Date: Mon Feb 11 17:05:57 2008 New Revision: 16 Modified: trunk/parser.lisp Log: Fix issue where *current-section* would be set to the section instance instead of the section name string. Also start implementing extended error information. Modified: trunk/parser.lisp ============================================================================== --- trunk/parser.lisp (original) +++ trunk/parser.lisp Mon Feb 11 17:05:57 2008 @@ -1,17 +1,24 @@ (cl:in-package #:py-configparser) +(declaim '(special *line-no* *current-section* *file-name* + *current-input*)) + ;; Errors for the parsing side -(define-condition parsing-error (configparser-error) ()) +(define-condition parsing-error (configparser-error) + ((line-no :initarg :line-no :initform *line-no* :reader line) + (file :initarg :file :initform *file-name* :reader file) + (section :initarg :section :initform *current-section* :reader section) + (message :initarg :text :reader message)) + (:report (lambda (c stream) + (format stream "~A at line ~A" (message c) (line c))))) (define-condition missing-section-header-error (parsing-error) ()) ;; The reader -(declaim '(special *line-no* *current-section* *file-name* - *current-input*)) (declaim '(inline %read-char %unread-char)) (defun %read-char (stream) @@ -69,7 +76,8 @@ while (is-whitespace c) finally (setf ch c))) (unless (member ch expect-bag) - (error 'parsing-error)) ;; character ch found, but looking for EXPECT-BAG + ;; character ch found, but looking for EXPECT-BAG + (error 'parsing-error)) ch)) (defun make-input-buffer (p) @@ -143,7 +151,7 @@ until (eq c :eof) if (eql c #\[) do (setf *current-section* - (ensure-section p (read-section-name p s))) + (section-name (ensure-section p (read-section-name p s)))) else if (is-whitespace c) do (skip-empty-line s) From ehuelsmann at common-lisp.net Mon Feb 11 22:07:41 2008 From: ehuelsmann at common-lisp.net (ehuelsmann at common-lisp.net) Date: Mon, 11 Feb 2008 17:07:41 -0500 (EST) Subject: [py-configparser-cvs] r17 - branches/1.0.x Message-ID: <20080211220741.467115D086@common-lisp.net> Author: ehuelsmann Date: Mon Feb 11 17:07:41 2008 New Revision: 17 Modified: branches/1.0.x/parser.lisp Log: Port r16 fix to 1.0.x branch. Modified: branches/1.0.x/parser.lisp ============================================================================== --- branches/1.0.x/parser.lisp (original) +++ branches/1.0.x/parser.lisp Mon Feb 11 17:07:41 2008 @@ -143,7 +143,7 @@ until (eq c :eof) if (eql c #\[) do (setf *current-section* - (ensure-section p (read-section-name p s))) + (section-name (ensure-section p (read-section-name p s)))) else if (is-whitespace c) do (skip-empty-line s) From ehuelsmann at common-lisp.net Mon Feb 11 22:24:34 2008 From: ehuelsmann at common-lisp.net (ehuelsmann at common-lisp.net) Date: Mon, 11 Feb 2008 17:24:34 -0500 (EST) Subject: [py-configparser-cvs] r18 - trunk Message-ID: <20080211222434.73D614083@common-lisp.net> Author: ehuelsmann Date: Mon Feb 11 17:24:34 2008 New Revision: 18 Modified: trunk/parser.lisp Log: Add error text messages as made possible per the last trunk commit. Modified: trunk/parser.lisp ============================================================================== --- trunk/parser.lisp (original) +++ trunk/parser.lisp Mon Feb 11 17:24:34 2008 @@ -51,7 +51,8 @@ (loop for c = (%read-char s) if (eq c #\Newline) do (return) else unless (is-whitespace c) - do (error 'parsing-error))) ;; empty line expected + do (error 'parsing-error + :text "Non-empty line found where empty expected."))) ;; empty line expected (defun skip-to-eol (s) (loop for c = (%read-char s) @@ -65,7 +66,9 @@ while (is-whitespace c) finally (setf ch c))) (unless (eq ch expect) - (error 'parsing-error)) ;; character expect expected, but ch found + (error 'parsing-error + :text (format nil "Character ~A expected, but ~A found instead." + expect ch))) ;; character expect expected, but ch found ch)) (defun expect-one-of (s expect-bag &key skip-whitespace) @@ -77,7 +80,9 @@ finally (setf ch c))) (unless (member ch expect-bag) ;; character ch found, but looking for EXPECT-BAG - (error 'parsing-error)) + (error 'parsing-error + :text (format nil "Character ~A found, but one of ~A expected." + ch expect-bag))) ch)) (defun make-input-buffer (p) @@ -99,7 +104,9 @@ (expect-char s #\[) (loop for c = (%read-char s) if (eq c #\Newline) - do (error 'parsing-error) ;; we can't have newlines in section names! + do (error 'parsing-error + :text "Premature end of line, or end of line in section name.") + ;; we can't have newlines in section names! else if (eq c #\]) do (progn (skip-to-eol s) @@ -112,7 +119,8 @@ (eq c #\=)) do (let ((option-name (finalize-input p))) (when (= 0 (length option-name)) - (error 'parsing-error)) ;; No option name found + (error 'parsing-error + :text "No option name found.")) ;; No option name found (return option-name)) else if (is-whitespace c) do (unread-char (expect-one-of s '(#\: #\=) :skip-whitespace t) s) @@ -163,7 +171,8 @@ do (%read-char s) ;; skip over the newline character else do (if (null *current-section*) - (error 'missing-section-header-error) + (error 'missing-section-header-error + :text (format nil "Missing section header; found ~A instead." c)) (set-option p *current-section* (read-option-name p s)