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 ;
11 : check-example ( element -- )
13 but-last "\n" join 1vector
16 [ eval>string ] with-datastack
17 ] with-scope peek "\n" ?tail drop
21 : check-examples ( word element -- )
22 nip \ $example swap elements [ check-example ] each ;
24 : extract-values ( element -- seq )
25 \ $values swap elements dup empty? [
26 first rest [ first ] map prune natural-sort
29 : effect-values ( word -- seq )
31 [ in>> ] [ out>> ] bi append
32 [ dup pair? [ first ] when effect>string ] map
35 : contains-funky-elements? ( element -- ? )
42 } swap '[ _ elements empty? not ] contains? ;
44 : check-values ( word element -- )
46 [ drop "declared-effect" word-prop not ]
47 [ nip contains-funky-elements? ]
50 [ effect-values >array ]
51 [ extract-values >array ]
54 } 2|| [ "$values don't match stack effect" throw ] unless ;
56 : check-see-also ( word element -- )
57 nip \ $see-also swap elements [
58 rest dup prune [ length ] bi@ assert=
61 : vocab-exists? ( name -- ? )
62 dup vocab swap "all-vocabs" get member? or ;
64 : check-modules ( element -- )
65 \ $vocab-link swap elements [
67 vocab-exists? [ "$vocab-link to non-existent vocabulary" throw ] unless
70 : check-rendering ( element -- )
71 [ print-topic ] with-string-writer drop ;
73 : all-word-help ( words -- seq )
74 [ word-help ] filter ;
76 TUPLE: help-error topic error ;
78 C: <help-error> help-error
81 "In " write dup topic>> pprint nl
84 : check-something ( obj quot -- )
85 flush [ <help-error> , ] recover ; inline
87 : check-word ( word -- )
95 [ [ check-rendering ] [ check-modules ] bi* ]
101 : check-words ( words -- ) [ check-word ] each ;
103 : check-article ( article -- )
106 '[ _ check-rendering _ check-modules ]
110 : files>vocabs ( -- assoc )
112 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
113 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
116 : group-articles ( -- assoc )
122 [ first _ at _ push-at ] [ 2drop ] if
126 : check-about ( vocab -- )
127 [ vocab-help [ article drop ] when* ] check-something ;
129 : check-vocab ( vocab -- seq )
130 "Checking " write dup write "..." print
133 [ words [ check-word ] each ]
134 [ "vocab-articles" get at [ check-article ] each ]
138 : run-help-lint ( prefix -- alist )
140 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
141 group-articles "vocab-articles" set
143 [ dup check-vocab ] { } map>assoc
144 [ nip empty? not ] assoc-filter
147 : typos. ( assoc -- )
149 "==== ALL CHECKS PASSED" print
153 [ print-error nl ] each
157 : help-lint ( prefix -- ) run-help-lint typos. ;
159 : help-lint-all ( -- ) "" help-lint ;
161 : unlinked-words ( words -- seq )
162 all-word-help [ article-parent not ] filter ;
164 : linked-undocumented-words ( -- seq )
166 [ word-help not ] filter
167 [ article-parent ] filter
168 [ "predicating" word-prop not ] filter ;