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 values ;
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 : don't-check-word? ( word -- ? )
51 [ "declared-effect" word-prop not ]
54 : check-values ( word element -- )
58 [ contains-funky-elements? ]
65 } 2|| [ "$values don't match stack effect" throw ] unless ;
67 : check-see-also ( word element -- )
68 nip \ $see-also swap elements [
69 rest dup prune [ length ] bi@ assert=
72 : vocab-exists? ( name -- ? )
73 [ vocab ] [ "all-vocabs" get member? ] bi or ;
75 : check-modules ( element -- )
76 \ $vocab-link swap elements [
78 vocab-exists? [ "$vocab-link to non-existent vocabulary" throw ] unless
81 : check-rendering ( element -- )
82 [ print-topic ] with-string-writer drop ;
84 : all-word-help ( words -- seq )
85 [ word-help ] filter ;
87 TUPLE: help-error topic error ;
89 C: <help-error> help-error
92 "In " write dup topic>> pprint nl
95 : check-something ( obj quot -- )
96 flush [ <help-error> , ] recover ; inline
98 : check-word ( word -- )
106 [ [ check-rendering ] [ check-modules ] bi* ]
112 : check-words ( words -- ) [ check-word ] each ;
114 : check-article ( article -- )
117 '[ _ check-rendering _ check-modules ]
121 : files>vocabs ( -- assoc )
123 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
124 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
127 : group-articles ( -- assoc )
133 [ first _ at _ push-at ] [ 2drop ] if
137 : check-about ( vocab -- )
138 [ vocab-help [ article drop ] when* ] check-something ;
140 : check-vocab ( vocab -- seq )
141 "Checking " write dup write "..." print
144 [ words [ check-word ] each ]
145 [ "vocab-articles" get at [ check-article ] each ]
149 : run-help-lint ( prefix -- alist )
151 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
152 group-articles "vocab-articles" set
154 [ dup check-vocab ] { } map>assoc
155 [ nip empty? not ] assoc-filter
158 : typos. ( assoc -- )
160 "==== ALL CHECKS PASSED" print
164 [ print-error nl ] each
168 : help-lint ( prefix -- ) run-help-lint typos. ;
170 : help-lint-all ( -- ) "" help-lint ;
172 : unlinked-words ( words -- seq )
173 all-word-help [ article-parent not ] filter ;
175 : linked-undocumented-words ( -- seq )
177 [ word-help not ] filter
178 [ article-parent ] filter
179 [ "predicating" word-prop not ] filter ;