(module datatype-registry-data mzscheme
(define-struct datatype (name variants))
(define-struct variant (name fields))
(define (unparse-datatype dt)
(unless (datatype? dt)
(error 'unparse-datatype "expected datatype"))
(cons (datatype-name dt)
(map (lambda (v)
(list (variant-name v)
(variant-fields v)))
(datatype-variants dt))))
(define (parse-datatype stx)
(syntax-case stx ()
[(type [variant (field ...)] ...)
#'(let ([certify (syntax-local-certifier)])
(make-datatype (certify #'type)
(list (make-variant (certify #'variant)
(list (certify #'field) ...))
...)))]))
(provide (all-defined)))