diff --git a/collects/xml/plist.ss b/collects/xml/plist.ss index 1f286f0a0d..d7b7d27b20 100644 --- a/collects/xml/plist.ss +++ b/collects/xml/plist.ss @@ -15,6 +15,29 @@ ; an array : (list 'array value ...) ; (we're ignoring data & date) + (define (plist-dict? v) + (and (list? v) + (pair? v) + (eq? (car v) 'dict) + (andmap (lambda (v) + (and (list? v) + (= 3 (length v)) + (eq? (car v) 'assoc-pair) + (string? (cadr v)) + (let pl-value? ([v (caddr v)]) + (or (string? v) + (and (pair? v) + (case (car v) + [(true) (null? (cdr v))] + [(false) (null? (cdr v))] + [(integer) (and (= (length v) 2) + (exact-integer? (cadr v)))] + [(real) (and (= (length v) 2) + (real? (cadr v)))] + [(array) (andmap pl-value? (cdr v))] + [else (plist-dict? v)])))))) + (cdr v)))) + ; raise-plist-exn : string mark-set xexpr symbol -> ??? (define (raise-plist-exn tag mark-set xexpr type) @@ -191,5 +214,5 @@ ;; END OF TEST - (provide read-plist) - (provide/contract [write-plist (xexpr/c output-port? . -> . void?)])) + (provide plist-dict? read-plist) + (provide/contract [write-plist (plist-dict? output-port? . -> . void?)])) diff --git a/collects/xml/xml.scrbl b/collects/xml/xml.scrbl index 4420be8888..cb7a123ff0 100644 --- a/collects/xml/xml.scrbl +++ b/collects/xml/xml.scrbl @@ -359,9 +359,8 @@ used to store dictionaries of string--value associations. This format is used by Mac OS X (both the operating system and its applications) to store all kinds of data. -A @deftech{dictionary X-expression} is an @tech{X-expression} that -could be create by an expression matching the following -@scheme[_dict-expr] grammar: +A @deftech{plist dictionary} is a value that could be created by an +expression matching the following @scheme[_dict-expr] grammar: @schemegrammar*[ #:literals (list) @@ -376,16 +375,18 @@ could be create by an expression matching the following (list 'array pl-value ...)] ] -@defproc[(read-plist [in input-port?]) xexpr/c]{ +@defproc[(plist-dict? [any/c v]) boolean?]{ -Reads a plist from a port, and produces a @tech{dictionary -X-expression}.} +Returns @scheme[#t] if @scheme[v] is a @tech{plist dictionary}, +@scheme[#f] otherwise.} -@defproc[(write-plist [dict xexpr/c] [out output-port?]) void?]{ +@defproc[(read-plist [in input-port?]) plist-dict?]{ -Write a plist to the given port. If @scheme[dict] is not a -@tech{dictionary X-expression}, the @scheme[exn:fail:contract] -exception is raised.} +Reads a plist from a port, and produces a @tech{plist dictionary}.} + +@defproc[(write-plist [dict plist-dict?] [out output-port?]) void?]{ + +Write a @tech{plist dictionary} to the given port.} @examples[ #:eval plist-eval