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 ( 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
113 [ first _ at _ push-at ] [ 2drop ] if
117 : check-about ( vocab -- )
118 [ vocab-help [ article drop ] when* ] check-something ;
120 : check-vocab ( vocab -- seq )
121 "Checking " write dup write "..." print
124 [ words [ check-word ] each ]
125 [ "vocab-articles" get at [ check-article ] each ]
129 : run-help-lint ( prefix -- alist )
131 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
132 group-articles "vocab-articles" set
134 [ dup check-vocab ] { } map>assoc
135 [ nip empty? not ] assoc-filter
138 : typos. ( assoc -- )
140 "==== ALL CHECKS PASSED" print
148 : help-lint ( prefix -- ) run-help-lint typos. ;
150 : help-lint-all ( -- ) "" help-lint ;
152 : unlinked-words ( words -- seq )
153 all-word-help [ article-parent not ] filter ;
155 : linked-undocumented-words ( -- seq )
157 [ word-help not ] filter
158 [ article-parent ] filter
159 [ "predicating" word-prop not ] filter ;