export-lists.rkt (3267B)
1 #lang racket 2 3 (require scribble/xref 4 setup/xref 5 racket/syntax 6 rackunit) 7 8 (provide module->all-exported-names 9 module->documented-exported-names 10 module->undocumented-exported-names 11 has-docs?) 12 13 (define xref (load-collections-xref)) 14 15 (define (phase-exported-names phase-exports) 16 (map first phase-exports)) 17 18 (define (phase-exports->names exports) 19 (map first 20 (apply append (map (curryr drop 1) exports)))) 21 22 (define (has-docs? mod binding) 23 (not (not (xref-binding->definition-tag xref (list mod binding) #f)))) 24 25 (module+ test 26 (check-true (has-docs? 'racket/list 'second)) 27 (check-false (has-docs? 'racket/match 'match-...-nesting))) 28 29 (define (module->all-exported-names mod) 30 (let-values ([(exp-values exp-syntax) (module->exports mod)]) 31 (append (phase-exports->names exp-values) 32 (phase-exports->names exp-syntax)))) 33 34 (module+ test 35 (check-equal? (module->all-exported-names 'racket/match) 36 '(legacy-match-expander? 37 match-...-nesting 38 match-expander? 39 prop:legacy-match-expander 40 prop:match-expander 41 syntax-local-match-introduce 42 exn:misc:match? 43 match-equality-test 44 match-define-values 45 define-match-expander 46 match 47 define/match 48 match*/derived 49 match/derived 50 match/values 51 match-letrec 52 match-define 53 match-let*-values 54 match-let-values 55 match-let* 56 match-let 57 match-lambda** 58 match-lambda 59 match* 60 failure-cont 61 == 62 struct* 63 match-lambda*))) 64 65 (define (module->documented-exported-names mod) 66 (filter (curry has-docs? mod) 67 (module->all-exported-names mod))) 68 69 (module+ test 70 (check-equal? (module->documented-exported-names 'racket/match) 71 '(legacy-match-expander? 72 match-expander? 73 prop:legacy-match-expander 74 prop:match-expander 75 syntax-local-match-introduce 76 exn:misc:match? 77 match-equality-test 78 match-define-values 79 define-match-expander 80 match 81 define/match 82 match*/derived 83 match/derived 84 match/values 85 match-letrec 86 match-define 87 match-let*-values 88 match-let-values 89 match-let* 90 match-let 91 match-lambda** 92 match-lambda 93 match* 94 failure-cont 95 == 96 struct* 97 match-lambda*))) 98 99 (define (module->undocumented-exported-names mod) 100 (filter-not (curry has-docs? mod) 101 (module->all-exported-names mod))) 102 103 (module+ test 104 (check-equal? (module->undocumented-exported-names 'racket/match) 105 '(match-...-nesting)))