|
|
@ -4,22 +4,23 @@
|
|
|
|
(provide (all-defined-out))
|
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
|
|
|
|
(define (split-metas x [meta-key 'define-meta])
|
|
|
|
(define (split-metas x [meta-key 'define-meta])
|
|
|
|
(apply hasheq
|
|
|
|
(let loop ([x ((if (syntax? x) syntax->datum values) x)])
|
|
|
|
(let loop ([x ((if (syntax? x) syntax->datum values) x)])
|
|
|
|
(match x
|
|
|
|
(match x
|
|
|
|
[(list (== meta-key eq?) key)
|
|
|
|
[(list (== meta-key eq?) key val)
|
|
|
|
(raise-argument-error meta-key "meta value missing" key)]
|
|
|
|
(unless (symbol? key)
|
|
|
|
[(list (== meta-key eq?) key val)
|
|
|
|
(raise-argument-error meta-key "valid meta key" key))
|
|
|
|
(unless (symbol? key)
|
|
|
|
(list key val)]
|
|
|
|
(raise-argument-error meta-key "valid meta key" key))
|
|
|
|
[(? list? xs) (append-map loop xs)]
|
|
|
|
(list (cons key val))]
|
|
|
|
[_ null]))))
|
|
|
|
[(? list? xs) (append-map loop xs)]
|
|
|
|
|
|
|
|
[_ null])))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(require rackunit)
|
|
|
|
(require rackunit)
|
|
|
|
(check-equal? (split-metas 'root) (hasheq))
|
|
|
|
(check-equal? (split-metas 'root) null)
|
|
|
|
(check-equal? (split-metas '(root)) (hasheq))
|
|
|
|
(check-equal? (split-metas '(root)) null)
|
|
|
|
(check-exn exn:fail:contract? (λ () (split-metas '(root (define-meta 42 "bar")))))
|
|
|
|
(check-exn exn:fail:contract? (λ () (split-metas '(root (define-meta 42 "bar")))))
|
|
|
|
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo "bar") "hi") "zim" (define-meta foo "boing") "zam")) '#hasheq((foo . "boing")))
|
|
|
|
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo "bar") "hi") "zim" (define-meta foo "boing") "zam")) '((foo . "bar") (foo . "boing")))
|
|
|
|
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo 'bar) "hi") "zim" (define-meta foo 'boing) "zam")) '#hasheq((foo . 'boing)))
|
|
|
|
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo 'bar) "hi") "zim" (define-meta foo 'boing) "zam")) '((foo . 'bar) (foo . 'boing)))
|
|
|
|
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (define-meta dog "Lex"))) '#hasheq((dog . "Lex")))
|
|
|
|
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (define-meta dog "Lex"))) '((dog . "Roxy") (dog . "Lex")))
|
|
|
|
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (div (define-meta dog "Lex")))) '#hasheq((dog . "Lex"))))
|
|
|
|
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (div (define-meta dog "Lex")))) '((dog . "Roxy") (dog . "Lex"))))
|