Skip to content
Snippets Groups Projects
Commit f1c2f059 authored by João Távora's avatar João Távora
Browse files

Fix SAFE-SIMPLE-READ-FROM-StrING

READER-ERROR doesn't take usual SIMPLE-ERROR args. (it does in Allegro though)

* safe-simple-read.lisp (snooze-reader-error): New error
condition.
(read-string, parse-symbol)
(safe-simple-read-from-string): Use it.
parent dcc6e665
No related branches found
No related tags found
No related merge requests found
(in-package #:snooze-safe-simple-read)
(define-condition snooze-reader-error (simple-error reader-error) ())
(defun parse-integer-then-float (string)
(let (retval nread)
(multiple-value-setq (retval nread)
......@@ -15,7 +17,7 @@
(defun read-string (stream &optional (terminator #\") )
(unless (eq (read-char stream) terminator)
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a cannot read string that doesn't start with ~a"
:format-arguments (list 'parse-string terminator)))
(let ((nread 1))
......@@ -32,7 +34,7 @@
(t
(write-char c)))))
(end-of-file (e)
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a sees premature end reading string inside string (~a)"
:format-arguments (list 'parse-string e))))
nread)))
......@@ -76,27 +78,29 @@
count 1
finally (unread-char c stream))
(end-of-file (e)
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a sees a colon ending reading symbol from string ~a (~a)"
:format-arguments (list 'parse-symbol string e)))))
(cond ((= ncolons 0)
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a expecting colons reading symbol from string ~a"
:format-arguments (list 'parse-symbol string)))
((> ncolons 2)
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a sees too many colons reading symbol from string ~a"
:format-arguments (list 'parse-symbol string))))
(setq package (or (find-package name)
(error 'reader-error
:format-control "~a sees does not recognize package ~a"
(setq package (or (and (zerop (length name))
#.(find-package :keyword))
(find-package name)
(error 'snooze-reader-error
:format-control "~a does not recognize package ~a"
:format-arguments (list 'parse-symbol name))))
(multiple-value-bind (name more-nread)
(read-name stream)
(setq symbol-name name
nread (+ ncolons nread more-nread))
(when (/= nread (length string))
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a sees garbage reading symbol from string ~a"
:format-arguments (list 'parse-symbol string)))))
(t
......@@ -106,7 +110,7 @@
(when (and (eq status :internal)
ncolons
(/= ncolons 2))
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a sees a symbol ~a not external in the ~a package"
:format-arguments (list 'parse-symbol symbol-name package)))
(values symbol status symbol-name package))))
......@@ -132,7 +136,7 @@ is never interned anywhere"
(multiple-value-bind (obj nread)
(read-string stream #\")
(unless (= nread (length string))
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a sees junk reading string inside string ~s"
:format-arguments (list 'safe-read-simple-token-from-string string)))
(values obj nread))))
......@@ -149,7 +153,7 @@ is never interned anywhere"
(if make-symbol-p
(values (make-symbol symbol-name)
(length string))
(error 'reader-error
(error 'snooze-reader-error
:format-control "~a refusing to intern a new symbol ~s in ~a"
:format-arguments `(safe-simple-read-from-string
,string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment