better error msg when token type is whitespace (fixes #9)

pull/14/head
Matthew Butterick 6 years ago
parent e6b8f99316
commit 359da840b9

@ -28,7 +28,10 @@
(lambda (tok-type tok-value offset line column span)
(raise (exn:fail:parsing
(string-append
(format "Encountered unexpected token ~e (~e) while parsing" tok-type tok-value)
(format "Encountered unexpected token of type ~e (value ~e) while parsing"
(if (memq tok-type (map string->symbol '("\n" "\t" "\r")))
(format "~a" tok-type)
tok-type) tok-value)
(if (or (current-source) line column offset)
(format " ~e [line=~a, column=~a, offset=~a]" (current-source) line column offset)
""))

@ -46,5 +46,5 @@
(check-exn exn:fail:parsing?
(lambda () (parse '("zero" "one" "zero"))))
(check-exn (regexp (regexp-quote
"Encountered unexpected token \"zero\" (\"zero\") while parsing"))
"Encountered unexpected token of type \"zero\" (value \"zero\") while parsing"))
(lambda () (parse '("zero" "one" "zero"))))

Loading…
Cancel
Save