1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.tuple combinators
4 combinators.short-circuit debugger definitions effects eval fry
5 grouping help help.markup help.topics io io.streams.string
6 kernel macros namespaces sequences sequences.deep sets splitting
7 strings summary unicode.categories vocabs vocabs.loader words
8 words.constant words.symbol ;
9 FROM: sets => members ;
12 ERROR: simple-lint-error message ;
14 M: simple-lint-error summary message>> ;
16 M: simple-lint-error error. summary print ;
20 SYMBOL: vocab-articles
22 : check-example ( element -- )
26 [ (eval>string) ] call( code -- output )
30 ] vocabs-quot get call( quot -- ) ;
32 : check-examples ( element -- )
33 \ $example swap elements [ check-example ] each ;
35 : extract-values ( element -- seq )
36 \ $values swap elements dup empty? [
40 : extract-value-effects ( element -- seq )
41 \ $values swap elements dup empty? [
43 \ $quotation swap elements dup empty? [ drop f ] [
49 : effect-values ( word -- seq )
51 [ in>> ] [ out>> ] bi append
52 [ dup pair? [ first ] when effect>string ] map members ;
54 : effect-effects ( word -- seq )
57 [ second dup effect? [ effect>string ] [ drop f ] if ]
61 : contains-funky-elements? ( element -- ? )
69 } swap '[ _ elements empty? not ] any? ;
71 : don't-check-word? ( word -- ? )
76 [ "declared-effect" word-prop not ]
80 : check-values ( word element -- )
84 [ contains-funky-elements? ]
91 } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
93 : check-value-effects ( word element -- )
95 [ extract-value-effects ]
96 bi* [ 2dup and [ = ] [ 2drop t ] if ] 2all?
97 [ "$quotation documentation in $values don't match stack effect" simple-lint-error ]
100 : check-nulls ( element -- )
101 \ $values swap elements
102 null swap deep-member?
103 [ "$values should not contain null" simple-lint-error ] when ;
105 : check-see-also ( element -- )
106 \ $see-also swap elements [
107 rest all-unique? t assert=
110 : vocab-exists? ( name -- ? )
111 [ lookup-vocab ] [ all-vocabs get member? ] bi or ;
113 : check-modules ( element -- )
114 \ $vocab-link swap elements [
117 "$vocab-link to non-existent vocabulary"
122 : check-rendering ( element -- )
123 [ print-content ] with-string-writer drop ;
125 : check-strings ( str -- )
128 "Paragraph text should not contain \\n or \\t"
133 "Paragraph text should not contain double spaces"
138 : check-whitespace ( str1 str2 -- )
139 [ " " tail? ] [ " " head? ] bi* or
140 [ "Missing whitespace between strings" simple-lint-error ] unless ;
142 : check-bogus-nl ( element -- )
143 { { $nl } { { $nl } } } [ head? ] with any? [
144 "Simple element should not begin with a paragraph break"
148 : extract-slots ( elements -- seq )
149 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
152 : check-class-description ( word element -- )
153 \ $class-description swap elements over class? [
154 [ all-slots [ name>> ] map ] [ extract-slots ] bi*
155 [ swap member? not ] with filter [
156 ", " join "Described $slot does not exist: " prepend
161 "A word that is not a class has a $class-description"
166 : check-article-title ( article -- )
167 article-title first LETTER?
168 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
170 : check-elements ( element -- )
173 [ [ string? ] filter [ check-strings ] each ]
174 [ [ simple-element? ] filter [ check-elements ] each ]
175 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
178 : check-descriptions ( element -- )
179 { $description $class-description $var-description }
182 rest { { } { "" } } member?
183 [ "Empty $description" simple-lint-error ] when
187 : check-markup ( element -- )
193 [ check-descriptions ]
196 : files>vocabs ( -- assoc )
198 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
199 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
202 : group-articles ( -- assoc )
208 [ first _ at _ push-at ] [ 2drop ] if
212 : all-word-help ( words -- seq )
213 [ word-help ] filter ;