1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: fry accessors sequences parser kernel help help.markup
4 help.topics words strings classes tools.vocabs namespaces make
5 io io.streams.string prettyprint definitions arrays vectors
6 combinators combinators.short-circuit splitting debugger
7 hashtables sorting effects vocabs vocabs.loader assocs editors
8 continuations classes.predicate macros math sets eval
9 vocabs.parser words.symbol ;
12 : check-example ( element -- )
14 but-last "\n" join 1vector
17 [ eval>string ] with-datastack
18 ] with-scope peek "\n" ?tail drop
22 : check-examples ( word element -- )
23 nip \ $example swap elements [ check-example ] each ;
25 : extract-values ( element -- seq )
26 \ $values swap elements dup empty? [
27 first rest [ first ] map prune natural-sort
30 : effect-values ( word -- seq )
32 [ in>> ] [ out>> ] bi append
33 [ dup pair? [ first ] when effect>string ] map
36 : contains-funky-elements? ( element -- ? )
43 } swap '[ _ elements empty? not ] contains? ;
45 : check-values ( word element -- )
47 [ drop { [ symbol? ] [ macro? ] [ parsing-word? ] } 1|| ]
48 [ drop "declared-effect" word-prop not ]
49 [ nip contains-funky-elements? ]
51 [ effect-values >array ]
52 [ extract-values >array ]
55 } 2|| [ "$values don't match stack effect" throw ] unless ;
57 : check-see-also ( word element -- )
58 nip \ $see-also swap elements [
59 rest dup prune [ length ] bi@ assert=
62 : vocab-exists? ( name -- ? )
63 [ vocab ] [ "all-vocabs" get member? ] bi or ;
65 : check-modules ( element -- )
66 \ $vocab-link swap elements [
68 vocab-exists? [ "$vocab-link to non-existent vocabulary" throw ] unless
71 : check-rendering ( element -- )
72 [ print-topic ] with-string-writer drop ;
74 : all-word-help ( words -- seq )
75 [ word-help ] filter ;
77 TUPLE: help-error topic error ;
79 C: <help-error> help-error
82 "In " write dup topic>> pprint nl
85 : check-something ( obj quot -- )
86 flush [ <help-error> , ] recover ; inline
88 : check-word ( word -- )
96 [ [ check-rendering ] [ check-modules ] bi* ]
102 : check-words ( words -- ) [ check-word ] each ;
104 : check-article ( article -- )
107 '[ _ check-rendering _ check-modules ]
111 : files>vocabs ( -- assoc )
113 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
114 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
117 : group-articles ( -- assoc )
123 [ first _ at _ push-at ] [ 2drop ] if
127 : check-about ( vocab -- )
128 [ vocab-help [ article drop ] when* ] check-something ;
130 : check-vocab ( vocab -- seq )
131 "Checking " write dup write "..." print
134 [ words [ check-word ] each ]
135 [ "vocab-articles" get at [ check-article ] each ]
139 : run-help-lint ( prefix -- alist )
141 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
142 group-articles "vocab-articles" set
144 [ dup check-vocab ] { } map>assoc
145 [ nip empty? not ] assoc-filter
148 : typos. ( assoc -- )
150 "==== ALL CHECKS PASSED" print
154 [ print-error nl ] each
158 : help-lint ( prefix -- ) run-help-lint typos. ;
160 : help-lint-all ( -- ) "" help-lint ;
162 : unlinked-words ( words -- seq )
163 all-word-help [ article-parent not ] filter ;
165 : linked-undocumented-words ( -- seq )
167 [ word-help not ] filter
168 [ article-parent ] filter
169 [ "predicating" word-prop not ] filter ;