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
35 : eval-with-stack ( str -- output )
38 parser-quiet? on parse-string [
40 nl "--- Data stack:" print stack.
43 ] [ nip print-error ] recover
44 ] with-string-writer ;
46 : check-example ( element -- )
55 ] vocabs-quot get call( quot -- )
56 ] leaks members no-ui-disposables
58 dup [ class-of ] histogram-by
59 [ "Leaked resources: " write ... ] with-string-writer simple-lint-error
64 : check-examples ( element -- )
65 \ $example swap elements [ check-example ] each ;
67 : extract-values ( element -- seq )
68 \ $values swap elements
69 [ f ] [ first rest keys ] if-empty ;
71 : extract-value-effects ( element -- seq )
72 \ $values swap elements [ f ] [
74 \ $quotation swap elements [ f ] [
75 first second dup effect? [ effect>string ] when
80 : effect-values ( word -- seq )
82 [ in>> ] [ out>> ] bi append
83 [ dup pair? [ first ] when effect>string ] map members ;
85 : effect-effects ( word -- seq )
88 [ second dup effect? [ effect>string ] [ drop f ] if ]
92 : contains-funky-elements? ( element -- ? )
100 } swap '[ _ elements empty? not ] any? ;
102 : don't-check-word? ( word -- ? )
107 [ "declared-effect" word-prop not ]
109 [ "help" word-prop not ]
112 : skip-check-values? ( word element -- ? )
113 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
115 : check-values ( word element -- )
116 2dup skip-check-values? [ 2drop ] [
117 [ effect-values ] [ extract-values ] bi* 2dup
118 sequence= [ 2drop ] [
119 "$values don't match stack effect; expected %u, got %u" sprintf
124 : check-value-effects ( word element -- )
125 [ effect-effects ] [ extract-value-effects ] bi*
126 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
127 "$quotation stack effects in $values don't match"
131 : check-nulls ( element -- )
132 \ $values swap elements
133 null swap deep-member?
134 [ "$values should not contain null" simple-lint-error ] when ;
136 : check-see-also ( element -- )
137 \ $see-also swap elements [ rest all-unique? ] all?
138 [ "$see-also are not unique" simple-lint-error ] unless ;
140 : check-modules ( element -- )
141 \ $vocab-link swap elements [
144 "$vocab-link to non-existent vocabulary"
149 : check-slots-tables ( element -- )
150 \ $slots swap elements [ rest [ length 2 = ] all? ] all?
151 [ "$slots have too many values in at least one row" simple-lint-error ] unless ;
153 : check-rendering ( element -- )
154 [ print-content ] with-string-writer drop ;
156 : check-strings ( str -- )
159 "Paragraph text should not contain \\n or \\t"
164 "Paragraph text should not contain double spaces"
169 : check-whitespace ( str1 str2 -- )
170 [ " " tail? ] [ " " head? ] bi* or
171 [ "Missing whitespace between strings" simple-lint-error ] unless ;
173 : check-bogus-nl ( element -- )
174 { { $nl } { { $nl } } } [ head? ] with any? [
175 "Simple element should not begin with a paragraph break"
179 : extract-slots ( elements -- seq )
180 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
183 : check-class-description ( word element -- )
184 \ $class-description swap elements over class? [
186 dup struct-class? [ struct-slots ] [ all-slots ] if
188 ] [ extract-slots ] bi*
189 [ swap member? ] with reject [
190 ", " join "Described $slot does not exist: " prepend
195 "A word that is not a class has a $class-description"
200 : check-article-title ( article -- )
201 article-title first LETTER?
202 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
204 : check-elements ( element -- )
207 [ [ string? ] filter [ check-strings ] each ]
208 [ [ simple-element? ] filter [ check-elements ] each ]
209 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
212 : check-descriptions ( element -- )
213 { $description $class-description $var-description }
216 rest { { } { "" } } member?
217 [ "Empty $description" simple-lint-error ] when
221 : check-markup ( element -- )
227 [ check-descriptions ]
228 [ check-slots-tables ]
231 : files>vocabs ( -- assoc )
233 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
234 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
237 : group-articles ( -- assoc )
243 [ first _ at _ push-at ] [ 2drop ] if
247 : all-word-help ( words -- seq )
248 [ word-help ] filter ;