1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.struct
4 classes.tuple combinators combinators.short-circuit debugger
5 definitions effects eval formatting fry grouping help
6 help.markup help.topics io io.streams.string kernel macros math
7 namespaces sequences sequences.deep sets splitting strings
8 summary tools.destructors unicode vocabs vocabs.loader words
9 words.constant words.symbol ;
12 ERROR: simple-lint-error message ;
14 M: simple-lint-error summary message>> ;
16 M: simple-lint-error error. summary print ;
19 SYMBOL: vocab-articles
21 : no-ui-disposables ( seq -- seq' )
24 "line" "single-texture" "multi-texture"
28 : check-example ( element -- )
33 [ (eval>string) ] call( code -- output )
37 ] vocabs-quot get call( quot -- )
38 ] leaks members no-ui-disposables length [
39 "%d disposable(s) leaked in example" sprintf simple-lint-error
42 : check-examples ( element -- )
43 \ $example swap elements [ check-example ] each ;
45 : extract-values ( element -- seq )
46 \ $values swap elements
47 [ f ] [ first rest keys ] if-empty ;
49 : extract-value-effects ( element -- seq )
50 \ $values swap elements [ f ] [
52 \ $quotation swap elements [ f ] [
53 first second dup effect? [ effect>string ] when
58 : effect-values ( word -- seq )
60 [ in>> ] [ out>> ] bi append
61 [ dup pair? [ first ] when effect>string ] map members ;
63 : effect-effects ( word -- seq )
66 [ second dup effect? [ effect>string ] [ drop f ] if ]
70 : contains-funky-elements? ( element -- ? )
78 } swap '[ _ elements empty? not ] any? ;
80 : don't-check-word? ( word -- ? )
85 [ "declared-effect" word-prop not ]
87 [ "word-help" word-prop not ]
90 : skip-check-values? ( word element -- ? )
91 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
93 : check-values ( word element -- )
94 2dup skip-check-values? [ 2drop ] [
95 [ effect-values ] [ extract-values ] bi* 2dup
97 "$values don't match stack effect; expected %u, got %u" sprintf
102 : check-value-effects ( word element -- )
103 [ effect-effects ] [ extract-value-effects ] bi*
104 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
105 "$quotation stack effects in $values don't match"
109 : check-nulls ( element -- )
110 \ $values swap elements
111 null swap deep-member?
112 [ "$values should not contain null" simple-lint-error ] when ;
114 : check-see-also ( element -- )
115 \ $see-also swap elements [ rest all-unique? ] all?
116 [ "$see-also are not unique" simple-lint-error ] unless ;
118 : check-modules ( element -- )
119 \ $vocab-link swap elements [
122 "$vocab-link to non-existent vocabulary"
127 : check-rendering ( element -- )
128 [ print-content ] with-string-writer drop ;
130 : check-strings ( str -- )
133 "Paragraph text should not contain \\n or \\t"
138 "Paragraph text should not contain double spaces"
143 : check-whitespace ( str1 str2 -- )
144 [ " " tail? ] [ " " head? ] bi* or
145 [ "Missing whitespace between strings" simple-lint-error ] unless ;
147 : check-bogus-nl ( element -- )
148 { { $nl } { { $nl } } } [ head? ] with any? [
149 "Simple element should not begin with a paragraph break"
153 : extract-slots ( elements -- seq )
154 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
157 : check-class-description ( word element -- )
158 \ $class-description swap elements over class? [
160 dup struct-class? [ struct-slots ] [ all-slots ] if
162 ] [ extract-slots ] bi*
163 [ swap member? ] with reject [
164 ", " join "Described $slot does not exist: " prepend
169 "A word that is not a class has a $class-description"
174 : check-article-title ( article -- )
175 article-title first LETTER?
176 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
178 : check-elements ( element -- )
181 [ [ string? ] filter [ check-strings ] each ]
182 [ [ simple-element? ] filter [ check-elements ] each ]
183 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
186 : check-descriptions ( element -- )
187 { $description $class-description $var-description }
190 rest { { } { "" } } member?
191 [ "Empty $description" simple-lint-error ] when
195 : check-markup ( element -- )
201 [ check-descriptions ]
204 : files>vocabs ( -- assoc )
206 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
207 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
210 : group-articles ( -- assoc )
216 [ first _ at _ push-at ] [ 2drop ] if
220 : all-word-help ( words -- seq )
221 [ word-help ] filter ;