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 -- )
18 but-last "\n" join 1vector
19 [ (eval>string) ] with-datastack
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 ] contains? ;
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 contains?
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-markup ( element -- )
125 : all-word-help ( words -- seq )
126 [ word-help ] filter ;
128 TUPLE: help-error error topic ;
130 C: <help-error> help-error
133 [ "In " write topic>> pprint nl ]
137 : check-something ( obj quot -- )
138 flush '[ _ assert-depth ] swap '[ _ <help-error> , ] recover ; inline
140 : check-word ( word -- )
141 [ with-file-vocabs ] vocabs-quot set
146 [ nip [ check-nulls ] [ check-see-also ] [ check-markup ] tri ] 2bi
150 : check-words ( words -- ) [ check-word ] each ;
152 : check-article-title ( article -- )
153 article-title first LETTER?
154 [ "Article title must begin with a capital letter" throw ] unless ;
156 : check-article ( article -- )
157 [ with-interactive-vocabs ] vocabs-quot set
160 [ check-article-title ]
161 [ article-content check-markup ] bi
164 : files>vocabs ( -- assoc )
166 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
167 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
170 : group-articles ( -- assoc )
176 [ first _ at _ push-at ] [ 2drop ] if
180 : check-about ( vocab -- )
181 dup '[ _ vocab-help [ article drop ] when* ] check-something ;
183 : check-vocab ( vocab -- seq )
184 "Checking " write dup write "..." print
187 [ words [ check-word ] each ]
188 [ "vocab-articles" get at [ check-article ] each ]
192 : run-help-lint ( prefix -- alist )
194 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
195 group-articles "vocab-articles" set
197 [ dup check-vocab ] { } map>assoc
198 [ nip empty? not ] assoc-filter
201 : typos. ( assoc -- )
203 "==== ALL CHECKS PASSED" print
207 [ print-error nl ] each
211 : help-lint ( prefix -- ) run-help-lint typos. ;
213 : help-lint-all ( -- ) "" help-lint ;
215 : unlinked-words ( words -- seq )
216 all-word-help [ article-parent not ] filter ;
218 : linked-undocumented-words ( -- seq )
220 [ word-help not ] filter
221 [ article-parent ] filter
222 [ "predicating" word-prop not ] filter ;