[racket-dev] [plt] Push #25403: master branch updated

From: Carl Eastlund (cce at racket-lang.org)
Date: Tue Oct 2 13:58:13 EDT 2012

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.

Carl Eastlund

On Tue, Oct 2, 2012 at 1:46 PM, <cce at racket-lang.org> wrote:

> cce has updated `master' from 937c901ce7 to bc681836bc.
>   http://git.racket-lang.org/plt/937c901ce7..bc681836bc
>
> =====[ One Commit ]=====================================================
> Directory summary:
>   40.0% collects/json/tests/
>   60.0% collects/json/
>
> ~~~~~~~~~~
>
> bc68183 Carl Eastlund <cce at racket-lang.org> 2012-10-02 12:01
> :
> | Updating read-json to produce eof when appropriate.
> :
>   M collects/json/json.scrbl     | 5 +++--
>   M collects/json/main.rkt       | 5 +++--
>   M collects/json/tests/json.rkt | 7 +++++++
>
> =====[ Overall Diff ]===================================================
>
> collects/json/json.scrbl
> ~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/json/json.scrbl
> +++ NEW/collects/json/json.scrbl
> @@ -79,9 +79,10 @@ the @rfc for more information about JSON.
>
>  @defproc[(read-json [in input-port? (current-input-port)]
>                      [#:null jsnull any? (json-null)])
> -         jsexpr?]{
> +         (or/c jsexpr? eof-object?)]{
>    Reads a @tech{jsexpr} from a JSON-encoded input port @racket[in] as a
> -  Racket (immutable) value.}
> +  Racket (immutable) value, or produces @racket[eof] if only whitespace
> +  remains.}
>
>  @defproc[(string->jsexpr [str string?] [#:null jsnull any? (json-null)])
>           jsexpr?]{
>
> collects/json/main.rkt
> ~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/json/main.rkt
> +++ NEW/collects/json/main.rkt
> @@ -156,7 +156,7 @@
>        (list (string->symbol k) (read-json)))
>      (apply hasheq (apply append (read-list 'object #rx#"^}" read-pair))))
>    ;;
> -  (define (read-json)
> +  (define (read-json #:eof-ok? [eof-ok? #false])
>      (skip-whitespace)
>      (cond
>        [(regexp-try-match #px#"^true\\b"  i) #t]
> @@ -171,9 +171,10 @@
>                (cond [(equal? m #"\"") (read-string)]
>                      [(equal? m #"[")  (read-list 'array #rx#"^\\]"
> read-json)]
>                      [(equal? m #"{")  (read-hash)])))]
> +      [(and eof-ok? (regexp-try-match #px#"$" i)) eof]
>        [else (err "bad input")]))
>    ;;
> -  (read-json))
> +  (read-json #:eof-ok? #true))
>
>  ;;
> ----------------------------------------------------------------------------
>  ;; Convenience functions
>
> collects/json/tests/json.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/json/tests/json.rkt
> +++ NEW/collects/json/tests/json.rkt
> @@ -95,6 +95,13 @@
>          (string->jsexpr @T{ " \b\n\r\f\t\\\"\/ " }) => " \b\n\r\f\t\\\"/ "
>          (string->jsexpr @T{ "\uD834\uDD1E" }) => "\U1D11E"
>          (string->jsexpr @T{ "\ud834\udd1e" }) => "\U1d11e"
> +        ;; EOF detection
> +        (for/list ([je (in-port read-json
> +                                (open-input-string
> +                                  @T{ 1 [2,3] "four" }))])
> +          je)
> +        =>
> +        '(1 (2 3) "four")
>          ))
>
>  (test do (pred-tests)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20121002/50a073cc/attachment.html>

Posted on the dev mailing list.