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
5 combinators.smart continuations debugger definitions effects
6 eval formatting fry grouping help help.markup help.topics io
7 io.streams.string kernel macros math math.statistics namespaces
8 parser.notes prettyprint sequences sequences.deep sets splitting
9 strings summary tools.destructors unicode vocabs vocabs.loader
10 words words.constant words.symbol ;
13 ERROR: simple-lint-error message ;
15 M: simple-lint-error summary message>> ;
17 M: simple-lint-error error. summary print ;
20 SYMBOL: vocab-articles
22 : no-ui-disposables ( seq -- seq' )
25 "single-texture" "multi-texture" ! opengl.textures
27 "layout" ! ui.text.pango
28 "script-string" ! windows.uniscribe
29 "linux-monitor" ! github issue #2014, race condition in disposing of child monitors
33 : eval-with-stack ( str -- output )
36 parser-quiet? on parse-string [
38 nl "--- Data stack:" print stack.
41 ] [ nip print-error ] recover
42 ] with-string-writer ;
44 : check-example ( element -- )
53 ] vocabs-quot get call( quot -- )
54 ] leaks members no-ui-disposables
56 dup [ class-of ] histogram-by
57 [ "Leaked resources: " write ... ] with-string-writer simple-lint-error
62 : check-examples ( element -- )
63 \ $example swap elements [ check-example ] each ;
65 : extract-values ( element -- seq )
66 \ $values swap elements
67 [ f ] [ first rest keys ] if-empty ;
69 : extract-value-effects ( element -- seq )
70 \ $values swap elements [ f ] [
72 \ $quotation swap elements [ f ] [
73 first second dup effect? [ effect>string ] when
78 : effect-values ( word -- seq )
80 [ in>> ] [ out>> ] bi append
81 [ dup pair? [ first ] when effect>string ] map members ;
83 : effect-effects ( word -- seq )
86 [ second dup effect? [ effect>string ] [ drop f ] if ]
90 : contains-funky-elements? ( element -- ? )
98 } swap '[ _ elements empty? not ] any? ;
100 : don't-check-word? ( word -- ? )
105 [ "declared-effect" word-prop not ]
107 [ "help" word-prop not ]
110 : skip-check-values? ( word element -- ? )
111 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
113 : check-values ( word element -- )
114 2dup skip-check-values? [ 2drop ] [
115 [ effect-values ] [ extract-values ] bi* 2dup
116 sequence= [ 2drop ] [
117 "$values don't match stack effect; expected %u, got %u" sprintf
122 : check-value-effects ( word element -- )
123 [ effect-effects ] [ extract-value-effects ] bi*
124 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
125 "$quotation stack effects in $values don't match"
129 : check-nulls ( element -- )
130 \ $values swap elements
131 null swap deep-member?
132 [ "$values should not contain null" simple-lint-error ] when ;
134 : check-see-also ( element -- )
135 \ $see-also swap elements [ rest all-unique? ] all?
136 [ "$see-also are not unique" simple-lint-error ] unless ;
138 : check-modules ( element -- )
139 \ $vocab-link swap elements [
142 "$vocab-link to non-existent vocabulary"
147 : check-rendering ( element -- )
148 [ print-content ] with-string-writer drop ;
150 : check-strings ( str -- )
153 "Paragraph text should not contain \\n or \\t"
158 "Paragraph text should not contain double spaces"
163 : check-whitespace ( str1 str2 -- )
164 [ " " tail? ] [ " " head? ] bi* or
165 [ "Missing whitespace between strings" simple-lint-error ] unless ;
167 : check-bogus-nl ( element -- )
168 { { $nl } { { $nl } } } [ head? ] with any? [
169 "Simple element should not begin with a paragraph break"
173 : extract-slots ( elements -- seq )
174 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
177 : check-class-description ( word element -- )
178 \ $class-description swap elements over class? [
180 dup struct-class? [ struct-slots ] [ all-slots ] if
182 ] [ extract-slots ] bi*
183 [ swap member? ] with reject [
184 ", " join "Described $slot does not exist: " prepend
189 "A word that is not a class has a $class-description"
194 : check-article-title ( article -- )
195 article-title first LETTER?
196 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
198 : check-elements ( element -- )
201 [ [ string? ] filter [ check-strings ] each ]
202 [ [ simple-element? ] filter [ check-elements ] each ]
203 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
206 : check-descriptions ( element -- )
207 { $description $class-description $var-description }
210 rest { { } { "" } } member?
211 [ "Empty $description" simple-lint-error ] when
215 : check-markup ( element -- )
221 [ check-descriptions ]
224 : files>vocabs ( -- assoc )
226 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
227 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
230 : group-articles ( -- assoc )
236 [ first _ at _ push-at ] [ 2drop ] if
240 : all-word-help ( words -- seq )
241 [ word-help ] filter ;