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 "single-texture" "multi-texture" ! opengl.textures
26 "layout" ! ui.text.pango
27 "script-string" ! windows.uniscribe
31 : check-example ( element -- )
36 [ (eval>string) ] call( code -- output )
40 ] vocabs-quot get call( quot -- )
41 ] leaks members no-ui-disposables length [
42 "%d disposable(s) leaked in example" sprintf simple-lint-error
45 : check-examples ( element -- )
46 \ $example swap elements [ check-example ] each ;
48 : extract-values ( element -- seq )
49 \ $values swap elements
50 [ f ] [ first rest keys ] if-empty ;
52 : extract-value-effects ( element -- seq )
53 \ $values swap elements [ f ] [
55 \ $quotation swap elements [ f ] [
56 first second dup effect? [ effect>string ] when
61 : effect-values ( word -- seq )
63 [ in>> ] [ out>> ] bi append
64 [ dup pair? [ first ] when effect>string ] map members ;
66 : effect-effects ( word -- seq )
69 [ second dup effect? [ effect>string ] [ drop f ] if ]
73 : contains-funky-elements? ( element -- ? )
81 } swap '[ _ elements empty? not ] any? ;
83 : don't-check-word? ( word -- ? )
88 [ "declared-effect" word-prop not ]
90 [ "word-help" word-prop not ]
93 : skip-check-values? ( word element -- ? )
94 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
96 : check-values ( word element -- )
97 2dup skip-check-values? [ 2drop ] [
98 [ effect-values ] [ extract-values ] bi* 2dup
100 "$values don't match stack effect; expected %u, got %u" sprintf
105 : check-value-effects ( word element -- )
106 [ effect-effects ] [ extract-value-effects ] bi*
107 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
108 "$quotation stack effects in $values don't match"
112 : check-nulls ( element -- )
113 \ $values swap elements
114 null swap deep-member?
115 [ "$values should not contain null" simple-lint-error ] when ;
117 : check-see-also ( element -- )
118 \ $see-also swap elements [ rest all-unique? ] all?
119 [ "$see-also are not unique" simple-lint-error ] unless ;
121 : check-modules ( element -- )
122 \ $vocab-link swap elements [
125 "$vocab-link to non-existent vocabulary"
130 : check-rendering ( element -- )
131 [ print-content ] with-string-writer drop ;
133 : check-strings ( str -- )
136 "Paragraph text should not contain \\n or \\t"
141 "Paragraph text should not contain double spaces"
146 : check-whitespace ( str1 str2 -- )
147 [ " " tail? ] [ " " head? ] bi* or
148 [ "Missing whitespace between strings" simple-lint-error ] unless ;
150 : check-bogus-nl ( element -- )
151 { { $nl } { { $nl } } } [ head? ] with any? [
152 "Simple element should not begin with a paragraph break"
156 : extract-slots ( elements -- seq )
157 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
160 : check-class-description ( word element -- )
161 \ $class-description swap elements over class? [
163 dup struct-class? [ struct-slots ] [ all-slots ] if
165 ] [ extract-slots ] bi*
166 [ swap member? ] with reject [
167 ", " join "Described $slot does not exist: " prepend
172 "A word that is not a class has a $class-description"
177 : check-article-title ( article -- )
178 article-title first LETTER?
179 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
181 : check-elements ( element -- )
184 [ [ string? ] filter [ check-strings ] each ]
185 [ [ simple-element? ] filter [ check-elements ] each ]
186 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
189 : check-descriptions ( element -- )
190 { $description $class-description $var-description }
193 rest { { } { "" } } member?
194 [ "Empty $description" simple-lint-error ] when
198 : check-markup ( element -- )
204 [ check-descriptions ]
207 : files>vocabs ( -- assoc )
209 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
210 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
213 : group-articles ( -- assoc )
219 [ first _ at _ push-at ] [ 2drop ] if
223 : all-word-help ( words -- seq )
224 [ word-help ] filter ;