(module person-example racket/base (provide (except-out (all-defined-out) :decode-embedded :encode-embedded) (rename-out (:decode-embedded decode-embedded:person-example) (:encode-embedded encode-embedded:person-example))) (require preserves) (require preserves-schema/methods) (require preserves-schema/support) (require racket/match) (require racket/set) (require racket/dict) (require (only-in racket/generic define/generic)) (define :decode-embedded values) (define :encode-embedded values) (struct Date (year month day) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((Date ?year ?month ?day) (record 'date (list (*->preserve ?year) (*->preserve ?month) (*->preserve ?day)))))))) (define (parse-Date input) (match input ((and dest (record 'date (list (and ?year (? exact-integer?)) (and ?month (? exact-integer?)) (and ?day (? exact-integer?)) _ ...))) (Date ?year ?month ?day)) (_ eof))) (define parse-Date! (parse-success-or-error 'parse-Date parse-Date)) (struct Person (name birthday) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((Person ?name ?birthday) (record 'person (list (*->preserve ?name) (*->preserve ?birthday)))))))) (define (parse-Person input) (match input ((and dest (record 'person (list (and ?name (? string?)) (app parse-Date (and ?birthday (not (== eof)))) _ ...))) (Person ?name ?birthday)) (_ eof))) (define parse-Person! (parse-success-or-error 'parse-Person parse-Person)))