Improve error recovery

This commit is contained in:
Tony Garnock-Jones 2018-10-08 20:54:06 +01:00
parent 8dc6346c58
commit b25a17b148
1 changed files with 7 additions and 4 deletions

View File

@ -289,8 +289,9 @@
(define k (read-value))
(skip-whitespace)
(match (peek-char i)
[#\: (when (set? acc) (parse-error "Unexpected key/value separator in set"))
(read-char i)
[#\: (read-char i)
(when (set? acc)
(parse-error "Unexpected key/value separator in set"))
(define v (read-value))
(hash-set (or acc (hash)) k v)]
[_ (when (hash? acc) (parse-error "Missing expected key/value separator"))
@ -306,7 +307,9 @@
(? char? (or #\( #\) #\{ #\} #\[ #\]
#\" #\; #\, #\# #\: (== PIPE)
(? char-whitespace?))))
(string->symbol (list->string (reverse acc)))]
(if (null? acc)
(parse-error "Invalid character ~v at start of value; skipping" (read-char i))
(string->symbol (list->string (reverse acc))))]
[_ (read-raw-symbol (cons (read-char i) acc))]))
(define (read-base64-binary acc)
@ -484,7 +487,7 @@
(read-base64-binary '())]
[_
(parse-error "Invalid preserve value")])]
[#\: (parse-error "Unexpected key/value separator between items")]
[#\: (read-char i) (parse-error "Unexpected key/value separator between items")]
[_ (read-raw-symbol '())])))
(read-value))