say where a reader error was met
Every later stage's error says file:line, and the reader's said only what; an unclosed list, met at the end of the file, now names the line it opened on as well.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
(import (chicken condition)
|
||||
(chicken irregex)
|
||||
(chicken port)
|
||||
reader)
|
||||
|
||||
@@ -10,12 +11,18 @@
|
||||
(with-input-from-string string
|
||||
(lambda () (read-raw-forms 'stdin))))))))
|
||||
|
||||
(define (read-error string)
|
||||
"The message of the error reading STRING raises, or #f if it reads."
|
||||
(define (read-error-at string)
|
||||
"The message of the error reading STRING raises, where included, or
|
||||
#f if it reads."
|
||||
(handle-exceptions e ((condition-property-accessor 'exn 'message) e)
|
||||
(with-input-from-string string (lambda () (read-raw-forms 'stdin)))
|
||||
#f))
|
||||
|
||||
(define (read-error string)
|
||||
"The message of the error reading STRING raises, or #f if it reads."
|
||||
(let ((message (read-error-at string)))
|
||||
(and message (irregex-replace "^[^:]*:[0-9]+: " message ""))))
|
||||
|
||||
(define-syntax reader-test
|
||||
(syntax-rules ()
|
||||
((reader-test result string)
|
||||
@@ -123,6 +130,15 @@
|
||||
(test "Latin-1 is no exception" #t (string? (read-error "#\\é")))
|
||||
(reader-test '(#\a #\~ #\space) "#\\a #\\~ #\\space")
|
||||
|
||||
;; A reader error said what and not where, which the error of every
|
||||
;; later stage does
|
||||
(test "a reader error says where"
|
||||
"stdin:2: unknown escape"
|
||||
(read-error-at "(a)\n\"\\q\""))
|
||||
(test "an unclosed list, where it opened"
|
||||
"stdin:3: Unexpected end of input inside a list opened on line 2"
|
||||
(read-error-at "(a)\n(b\n (c)"))
|
||||
|
||||
;; `;' comments are preserved as (comment "...") forms
|
||||
(reader-test '((comment " hi")) "; hi")
|
||||
(reader-test '((comment ";; Prototypes")) ";;; Prototypes")
|
||||
|
||||
Reference in New Issue
Block a user