Oops, I hadn't meant to push that to the main repository without consulting anyone. Hope this change is okay, it seemed weird for read-json to error instead of producing eof.<br><br clear="all">Carl Eastlund<br><br><div class="gmail_quote">
On Tue, Oct 2, 2012 at 1:46 PM, <span dir="ltr"><<a href="mailto:cce@racket-lang.org" target="_blank">cce@racket-lang.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
cce has updated `master' from 937c901ce7 to bc681836bc.<br>
<a href="http://git.racket-lang.org/plt/937c901ce7..bc681836bc" target="_blank">http://git.racket-lang.org/plt/937c901ce7..bc681836bc</a><br>
<br>
=====[ One Commit ]=====================================================<br>
Directory summary:<br>
40.0% collects/json/tests/<br>
60.0% collects/json/<br>
<br>
~~~~~~~~~~<br>
<br>
bc68183 Carl Eastlund <<a href="mailto:cce@racket-lang.org">cce@racket-lang.org</a>> 2012-10-02 12:01<br>
:<br>
| Updating read-json to produce eof when appropriate.<br>
:<br>
M collects/json/json.scrbl | 5 +++--<br>
M collects/json/main.rkt | 5 +++--<br>
M collects/json/tests/json.rkt | 7 +++++++<br>
<br>
=====[ Overall Diff ]===================================================<br>
<br>
collects/json/json.scrbl<br>
~~~~~~~~~~~~~~~~~~~~~~~~<br>
--- OLD/collects/json/json.scrbl<br>
+++ NEW/collects/json/json.scrbl<br>
@@ -79,9 +79,10 @@ the @rfc for more information about JSON.<br>
<br>
@defproc[(read-json [in input-port? (current-input-port)]<br>
[#:null jsnull any? (json-null)])<br>
- jsexpr?]{<br>
+ (or/c jsexpr? eof-object?)]{<br>
Reads a @tech{jsexpr} from a JSON-encoded input port @racket[in] as a<br>
- Racket (immutable) value.}<br>
+ Racket (immutable) value, or produces @racket[eof] if only whitespace<br>
+ remains.}<br>
<br>
@defproc[(string->jsexpr [str string?] [#:null jsnull any? (json-null)])<br>
jsexpr?]{<br>
<br>
collects/json/main.rkt<br>
~~~~~~~~~~~~~~~~~~~~~~<br>
--- OLD/collects/json/main.rkt<br>
+++ NEW/collects/json/main.rkt<br>
@@ -156,7 +156,7 @@<br>
(list (string->symbol k) (read-json)))<br>
(apply hasheq (apply append (read-list 'object #rx#"^}" read-pair))))<br>
;;<br>
- (define (read-json)<br>
+ (define (read-json #:eof-ok? [eof-ok? #false])<br>
(skip-whitespace)<br>
(cond<br>
[(regexp-try-match #px#"^true\\b" i) #t]<br>
@@ -171,9 +171,10 @@<br>
(cond [(equal? m #"\"") (read-string)]<br>
[(equal? m #"[") (read-list 'array #rx#"^\\]" read-json)]<br>
[(equal? m #"{") (read-hash)])))]<br>
+ [(and eof-ok? (regexp-try-match #px#"$" i)) eof]<br>
[else (err "bad input")]))<br>
;;<br>
- (read-json))<br>
+ (read-json #:eof-ok? #true))<br>
<br>
;; ----------------------------------------------------------------------------<br>
;; Convenience functions<br>
<br>
collects/json/tests/json.rkt<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
--- OLD/collects/json/tests/json.rkt<br>
+++ NEW/collects/json/tests/json.rkt<br>
@@ -95,6 +95,13 @@<br>
(string->jsexpr @T{ " \b\n\r\f\t\\\"\/ " }) => " \b\n\r\f\t\\\"/ "<br>
(string->jsexpr @T{ "\uD834\uDD1E" }) => "\U1D11E"<br>
(string->jsexpr @T{ "\ud834\udd1e" }) => "\U1d11e"<br>
+ ;; EOF detection<br>
+ (for/list ([je (in-port read-json<br>
+ (open-input-string<br>
+ @T{ 1 [2,3] "four" }))])<br>
+ je)<br>
+ =><br>
+ '(1 (2 3) "four")<br>
))<br>
<br>
(test do (pred-tests)<br>
<br>
</blockquote></div><br>