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:
parent
b36b2ffda7
commit
8db930794d
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user