1 ! Copyright (C) 2006, 2009 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 grouping unicode.categories
15 : check-example ( element -- )
19 [ (eval>string) ] call( code -- output )
23 ] vocabs-quot get call ;
25 : check-examples ( element -- )
26 \ $example swap elements [ check-example ] each ;
28 : extract-values ( element -- seq )
29 \ $values swap elements dup empty? [
30 first rest [ first ] map prune natural-sort
33 : effect-values ( word -- seq )
35 [ in>> ] [ out>> ] bi append
36 [ dup pair? [ first ] when effect>string ] map
39 : contains-funky-elements? ( element -- ? )
46 } swap '[ _ elements empty? not ] any? ;
48 : don't-check-word? ( word -- ? )
54 [ "declared-effect" word-prop not ]
57 : check-values ( word element -- )
61 [ contains-funky-elements? ]
68 } 2|| [ "$values don't match stack effect" throw ] unless ;
70 : check-nulls ( element -- )
71 \ $values swap elements
72 null swap deep-member?
73 [ "$values should not contain null" throw ] when ;
75 : check-see-also ( element -- )
76 \ $see-also swap elements [
77 rest dup prune [ length ] bi@ assert=
80 : vocab-exists? ( name -- ? )
81 [ vocab ] [ "all-vocabs" get member? ] bi or ;
83 : check-modules ( element -- )
84 \ $vocab-link swap elements [
86 vocab-exists? [ "$vocab-link to non-existent vocabulary" throw ] unless
89 : check-rendering ( element -- )
90 [ print-content ] with-string-writer drop ;
92 : check-strings ( str -- )
95 [ "Paragraph text should not contain \\n or \\t" throw ] when
98 [ "Paragraph text should not contain double spaces" throw ] when
101 : check-whitespace ( str1 str2 -- )
102 [ " " tail? ] [ " " head? ] bi* or
103 [ "Missing whitespace between strings" throw ] unless ;
105 : check-bogus-nl ( element -- )
106 { { $nl } { { $nl } } } [ head? ] with any?
107 [ "Simple element should not begin with a paragraph break" throw ] when ;
109 : check-elements ( element -- )
112 [ [ string? ] filter [ check-strings ] each ]
113 [ [ simple-element? ] filter [ check-elements ] each ]
114 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
117 : check-descriptions ( element -- )
118 { $description $class-description $var-description }
121 rest { { } { "" } } member?
122 [ "Empty description" throw ] when
126 : check-markup ( element -- )
132 [ check-descriptions ]
135 : check-class-description ( word element -- )
137 [ { $class-description } swap elements empty? not ] bi* and
138 [ "A word that is not a class has a $class-description" throw ] when ;
140 : all-word-help ( words -- seq )
141 [ word-help ] filter ;
143 TUPLE: help-error error topic ;
145 C: <help-error> help-error
148 [ "In " write topic>> pprint nl ]
152 : check-something ( obj quot -- )
153 flush '[ _ call( -- ) ] swap '[ _ <help-error> , ] recover ; inline
155 : check-word ( word -- )
156 [ with-file-vocabs ] vocabs-quot set
161 [ check-class-description ]
162 [ nip [ check-nulls ] [ check-see-also ] [ check-markup ] tri ] 2tri
166 : check-words ( words -- ) [ check-word ] each ;
168 : check-article-title ( article -- )
169 article-title first LETTER?
170 [ "Article title must begin with a capital letter" throw ] unless ;
172 : check-article ( article -- )
173 [ with-interactive-vocabs ] vocabs-quot set
176 [ check-article-title ]
177 [ article-content check-markup ] bi
180 : files>vocabs ( -- assoc )
182 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
183 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
186 : group-articles ( -- assoc )
192 [ first _ at _ push-at ] [ 2drop ] if
196 : check-about ( vocab -- )
197 dup '[ _ vocab-help [ article drop ] when* ] check-something ;
199 : check-vocab ( vocab -- seq )
200 "Checking " write dup write "..." print
203 [ words [ check-word ] each ]
204 [ "vocab-articles" get at [ check-article ] each ]
208 : run-help-lint ( prefix -- alist )
210 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
211 group-articles "vocab-articles" set
213 [ dup check-vocab ] { } map>assoc
214 [ nip empty? not ] assoc-filter
217 : typos. ( assoc -- )
219 "==== ALL CHECKS PASSED" print
223 [ print-error nl ] each
227 : help-lint ( prefix -- ) run-help-lint typos. ;
229 : help-lint-all ( -- ) "" help-lint ;
231 : unlinked-words ( words -- seq )
232 all-word-help [ article-parent not ] filter ;
234 : linked-undocumented-words ( -- seq )
236 [ word-help not ] filter
237 [ article-parent ] filter
238 [ "predicating" word-prop not ] filter ;