passing it through to OPEN.
** LOAD on source files likewise passes any EXTERNAL-FORMAT
argument given to internal calls to OPEN.
+ ** the built-in comment readers (introduced by character sequences
+ ";" and "#|") are more forgiving to encoding errors; they will
+ STYLE-WARN and then attempt to resync the stream at a character
+ boundary. (thanks to Teemu Kalvas)
* fixed some bugs revealed by Paul Dietz' test suite:
** Space, Tab, Linefeed, Return and Page have the invalid
secondary constituent character trait.
(defun read-comment (stream ignore)
(declare (ignore ignore))
- (let ((stream (in-synonym-of stream)))
- (if (ansi-stream-p stream)
- (prepare-for-fast-read-char stream
- (do ((char (fast-read-char nil nil)
- (fast-read-char nil nil)))
- ((or (not char) (char= char #\newline))
- (done-with-fast-read-char))))
- ;; CLOS stream
- (do ((char (read-char stream nil :eof) (read-char stream nil :eof)))
- ((or (eq char :eof) (char= char #\newline))))))
+ (handler-bind
+ ((character-decoding-error
+ #'(lambda (decoding-error)
+ (declare (ignorable decoding-error))
+ (style-warn "Character decoding error in a ;-comment at position ~A reading source file ~A, resyncing." (file-position stream) stream)
+ (invoke-restart 'attempt-resync))))
+ (let ((stream (in-synonym-of stream)))
+ (if (ansi-stream-p stream)
+ (prepare-for-fast-read-char stream
+ (do ((char (fast-read-char nil nil)
+ (fast-read-char nil nil)))
+ ((or (not char) (char= char #\newline))
+ (done-with-fast-read-char))))
+ ;; CLOS stream
+ (do ((char (read-char stream nil :eof) (read-char stream nil :eof)))
+ ((or (eq char :eof) (char= char #\newline)))))))
;; Don't return anything.
(values))
(defun sharp-vertical-bar (stream sub-char numarg)
(ignore-numarg sub-char numarg)
- (let ((stream (in-synonym-of stream)))
- (if (ansi-stream-p stream)
- (prepare-for-fast-read-char stream
+ (handler-bind
+ ((character-decoding-error
+ #'(lambda (decoding-error)
+ (declare (ignorable decoding-error))
+ (style-warn "Character decoding error in a #|-comment at position ~A reading source file ~A, resyncing." (file-position stream) stream)
+ (invoke-restart 'attempt-resync))))
+ (let ((stream (in-synonym-of stream)))
+ (if (ansi-stream-p stream)
+ (prepare-for-fast-read-char stream
+ (do ((level 1)
+ (prev (fast-read-char) char)
+ (char (fast-read-char) (fast-read-char)))
+ (())
+ (cond ((and (char= prev #\|) (char= char #\#))
+ (setq level (1- level))
+ (when (zerop level)
+ (done-with-fast-read-char)
+ (return (values)))
+ (setq char (fast-read-char)))
+ ((and (char= prev #\#) (char= char #\|))
+ (setq char (fast-read-char))
+ (setq level (1+ level))))))
+ ;; fundamental-stream
(do ((level 1)
- (prev (fast-read-char) char)
- (char (fast-read-char) (fast-read-char)))
+ (prev (read-char stream t) char)
+ (char (read-char stream t) (read-char stream t)))
(())
(cond ((and (char= prev #\|) (char= char #\#))
(setq level (1- level))
(when (zerop level)
- (done-with-fast-read-char)
(return (values)))
- (setq char (fast-read-char)))
+ (setq char (read-char stream t)))
((and (char= prev #\#) (char= char #\|))
- (setq char (fast-read-char))
- (setq level (1+ level))))))
- ;; fundamental-stream
- (do ((level 1)
- (prev (read-char stream t) char)
- (char (read-char stream t) (read-char stream t)))
- (())
- (cond ((and (char= prev #\|) (char= char #\#))
- (setq level (1- level))
- (when (zerop level)
- (return (values)))
- (setq char (read-char stream t)))
- ((and (char= prev #\#) (char= char #\|))
- (setq char (read-char stream t))
- (setq level (1+ level))))))))
+ (setq char (read-char stream t))
+ (setq level (1+ level)))))))))
\f
;;;; a grab bag of other sharp readmacros: #', #:, and #.