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
5 formatting fry grouping help help.markup help.topics io io.streams.string
6 kernel macros math namespaces sequences sequences.deep sets splitting
7 strings summary threads tools.destructors unicode.categories vocabs vocabs.loader
8 words 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 -- )
27 [ (eval>string) ] call( code -- output )
31 ] vocabs-quot get call( quot -- )
32 ] leaks members length [
33 "%d disposable(s) leaked in example" sprintf simple-lint-error
36 : check-examples ( element -- )
37 \ $example swap elements [ check-example ] each ;
39 : extract-values ( element -- seq )
40 \ $values swap elements dup empty? [
44 : extract-value-effects ( element -- seq )
45 \ $values swap elements dup empty? [
47 \ $quotation swap elements dup empty? [ drop f ] [
53 : effect-values ( word -- seq )
55 [ in>> ] [ out>> ] bi append
56 [ dup pair? [ first ] when effect>string ] map members ;
58 : effect-effects ( word -- seq )
61 [ second dup effect? [ effect>string ] [ drop f ] if ]
65 : contains-funky-elements? ( element -- ? )
73 } swap '[ _ elements empty? not ] any? ;
75 : don't-check-word? ( word -- ? )
80 [ "declared-effect" word-prop not ]
84 : skip-check-values? ( word element -- ? )
85 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
87 : check-values ( word element -- )
88 2dup skip-check-values? [ 2drop ] [
89 [ effect-values ] [ extract-values ] bi* 2dup
91 "$values don't match stack effect; expected %u, got %u" sprintf
96 : check-value-effects ( word element -- )
98 [ extract-value-effects ]
99 bi* [ 2dup and [ = ] [ 2drop t ] if ] 2all?
100 [ "$quotation documentation in $values don't match stack effect" simple-lint-error ]
103 : check-nulls ( element -- )
104 \ $values swap elements
105 null swap deep-member?
106 [ "$values should not contain null" simple-lint-error ] when ;
108 : check-see-also ( element -- )
109 \ $see-also swap elements [
110 rest all-unique? t assert=
113 : vocab-exists? ( name -- ? )
114 [ lookup-vocab ] [ all-vocabs get member? ] bi or ;
116 : check-modules ( element -- )
117 \ $vocab-link swap elements [
120 "$vocab-link to non-existent vocabulary"
125 : check-rendering ( element -- )
126 [ print-content ] with-string-writer drop ;
128 : check-strings ( str -- )
131 "Paragraph text should not contain \\n or \\t"
136 "Paragraph text should not contain double spaces"
141 : check-whitespace ( str1 str2 -- )
142 [ " " tail? ] [ " " head? ] bi* or
143 [ "Missing whitespace between strings" simple-lint-error ] unless ;
145 : check-bogus-nl ( element -- )
146 { { $nl } { { $nl } } } [ head? ] with any? [
147 "Simple element should not begin with a paragraph break"
151 : extract-slots ( elements -- seq )
152 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
155 : check-class-description ( word element -- )
156 \ $class-description swap elements over class? [
157 [ all-slots [ name>> ] map ] [ extract-slots ] bi*
158 [ swap member? not ] with filter [
159 ", " join "Described $slot does not exist: " prepend
164 "A word that is not a class has a $class-description"
169 : check-article-title ( article -- )
170 article-title first LETTER?
171 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
173 : check-elements ( element -- )
176 [ [ string? ] filter [ check-strings ] each ]
177 [ [ simple-element? ] filter [ check-elements ] each ]
178 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
181 : check-descriptions ( element -- )
182 { $description $class-description $var-description }
185 rest { { } { "" } } member?
186 [ "Empty $description" simple-lint-error ] when
190 : check-markup ( element -- )
196 [ check-descriptions ]
199 : files>vocabs ( -- assoc )
201 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
202 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
205 : group-articles ( -- assoc )
211 [ first _ at _ push-at ] [ 2drop ] if
215 : all-word-help ( words -- seq )
216 [ word-help ] filter ;