1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00

Improve error reporting for EOF errors

This commit is contained in:
Iqbal Ansari 2016-08-15 15:46:26 +05:30
parent b36b2ffda7
commit 8db930794d
2 changed files with 16 additions and 6 deletions

View File

@ -27,7 +27,11 @@
"RE")
(define-condition eof (error)
((text :initarg :text)))
((context :initarg :context :reader context))
(:report (lambda (condition stream)
(format stream
"EOF encountered while reading ~a"
(context condition)))))
(defun test-re (re string)
(let ((match (regexp:match re string)))
@ -91,8 +95,10 @@
(loop
for token = (peek reader)
while (cond
((null token) (error 'eof :text (format "EOF encountered while reading list, expected ~a"
delimiter)))
((null token) (error 'eof
:context (if (string= delimiter ")")
"list"
"vector")))
((string= token delimiter) (return))
(t (push (read-form reader) forms))))
;; Consume the closing brace

View File

@ -16,9 +16,13 @@
(printer:pr-str expression))
(defun rep (string)
(handler-case (mal-print (mal-eval (mal-read string)
(make-hash-table :test #'equal)))
(reader::eof () "EOF occured")))
(handler-case
(mal-print (mal-eval (mal-read string)
(make-hash-table :test #'equal)))
(reader::eof (condition)
(format nil
"~a"
condition))))
(defun readline (prompt &optional (in-stream *standard-input*) (out-stream *standard-output*))
(format out-stream prompt)