|
|
@ -3,23 +3,23 @@
|
|
|
|
racket/list)
|
|
|
|
racket/list)
|
|
|
|
(provide (all-defined-out))
|
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
|
|
|
|
(define (split-metas x meta-key)
|
|
|
|
(define (split-metas x [meta-key 'define-meta])
|
|
|
|
(apply hasheq
|
|
|
|
(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 val)
|
|
|
|
[(list (== meta-key eq?) key val)
|
|
|
|
(unless (symbol? key)
|
|
|
|
(unless (symbol? key)
|
|
|
|
(raise-argument-error 'define-meta "valid meta key" key))
|
|
|
|
(raise-argument-error meta-key "valid meta key" key))
|
|
|
|
(list key val)]
|
|
|
|
(list key val)]
|
|
|
|
[(? list? xs) (append-map loop xs)]
|
|
|
|
[(? list? xs) (append-map loop xs)]
|
|
|
|
[_ null]))))
|
|
|
|
[_ null]))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(require rackunit)
|
|
|
|
(require rackunit)
|
|
|
|
(check-equal? (split-metas 'root 'define-meta) (hasheq))
|
|
|
|
(check-equal? (split-metas 'root) (hasheq))
|
|
|
|
(check-equal? (split-metas '(root) 'define-meta) (hasheq))
|
|
|
|
(check-equal? (split-metas '(root)) (hasheq))
|
|
|
|
(check-exn exn:fail:contract? (λ () (split-metas '(root (define-meta 42 "bar")) 'define-meta)))
|
|
|
|
(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") 'define-meta) '#hasheq((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") 'define-meta) '#hasheq((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 (define-meta dog "Roxy") (define-meta dog "Lex")) 'define-meta) '#hasheq((dog . "Lex")))
|
|
|
|
(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") (div (define-meta dog "Lex"))) 'define-meta) '#hasheq((dog . "Lex"))))
|
|
|
|
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (div (define-meta dog "Lex")))) '#hasheq((dog . "Lex"))))
|