1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors sequences parser kernel help help.markup
4 help.topics words strings classes tools.vocabs namespaces io
5 io.streams.string prettyprint definitions arrays vectors
6 combinators splitting debugger hashtables sorting effects vocabs
7 vocabs.loader assocs editors continuations classes.predicate
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 f like ] curry contains? ;
44 : check-values ( word element -- )
46 { [ over "declared-effect" word-prop ] [ 2drop ] }
47 { [ dup contains-funky-elements? not ] [ 2drop ] }
48 { [ over macro? not ] [ 2drop ] }
50 [ effect-values >array ]
51 [ extract-values >array ]
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 ( word element -- )
65 nip \ $vocab-link swap elements [
67 vocab-exists? [ "Missing vocabulary" throw ] unless
70 : check-rendering ( word element -- )
71 [ help ] 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 2dup drop check-rendering
100 : check-words ( words -- ) [ check-word ] each ;
102 : check-article ( article -- )
104 [ dup check-rendering ] assert-depth drop
107 : group-articles ( -- assoc )
109 vocabs [ dup vocab-docs-path swap ] H{ } map>assoc
112 >r >r dup >link where dup
113 [ first r> at r> push-at ]
114 [ r> r> 2drop 2drop ]
119 : check-about ( vocab -- )
120 [ vocab-help [ article drop ] when* ] check-something ;
122 : check-vocab ( vocab -- seq )
123 "Checking " write dup write "..." print
126 [ words [ check-word ] each ]
127 [ "vocab-articles" get at [ check-article ] each ]
131 : run-help-lint ( prefix -- alist )
133 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
134 articles get keys "group-articles" set
136 [ dup check-vocab ] { } map>assoc
137 [ nip empty? not ] assoc-filter
140 : typos. ( assoc -- )
143 "==== ALL CHECKS PASSED" print
151 : help-lint ( prefix -- ) run-help-lint typos. ;
153 : help-lint-all ( -- ) "" help-lint ;
155 : unlinked-words ( words -- seq )
156 all-word-help [ article-parent not ] filter ;
158 : linked-undocumented-words ( -- seq )
160 [ word-help not ] filter
161 [ article-parent ] filter
162 [ "predicating" word-prop not ] filter ;