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
32 : eval-with-stack ( str -- output )
35 parser-quiet? on parse-string [
37 nl "--- Data stack:" print stack.
40 ] [ nip print-error ] recover
41 ] with-string-writer ;
43 : check-example ( element -- )
52 ] vocabs-quot get call( quot -- )
53 ] leaks members no-ui-disposables
55 dup [ class-of ] histogram-by
56 [ "Leaked resources: " write ... ] with-string-writer simple-lint-error
61 : check-examples ( element -- )
62 \ $example swap elements [ check-example ] each ;
64 : extract-values ( element -- seq )
65 \ $values swap elements
66 [ f ] [ first rest keys ] if-empty ;
68 : extract-value-effects ( element -- seq )
69 \ $values swap elements [ f ] [
71 \ $quotation swap elements [ f ] [
72 first second dup effect? [ effect>string ] when
77 : effect-values ( word -- seq )
79 [ in>> ] [ out>> ] bi append
80 [ dup pair? [ first ] when effect>string ] map members ;
82 : effect-effects ( word -- seq )
85 [ second dup effect? [ effect>string ] [ drop f ] if ]
89 : contains-funky-elements? ( element -- ? )
97 } swap '[ _ elements empty? not ] any? ;
99 : don't-check-word? ( word -- ? )
104 [ "declared-effect" word-prop not ]
106 [ "help" word-prop not ]
109 : skip-check-values? ( word element -- ? )
110 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
112 : check-values ( word element -- )
113 2dup skip-check-values? [ 2drop ] [
114 [ effect-values ] [ extract-values ] bi* 2dup
115 sequence= [ 2drop ] [
116 "$values don't match stack effect; expected %u, got %u" sprintf
121 : check-value-effects ( word element -- )
122 [ effect-effects ] [ extract-value-effects ] bi*
123 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
124 "$quotation stack effects in $values don't match"
128 : check-nulls ( element -- )
129 \ $values swap elements
130 null swap deep-member?
131 [ "$values should not contain null" simple-lint-error ] when ;
133 : check-see-also ( element -- )
134 \ $see-also swap elements [ rest all-unique? ] all?
135 [ "$see-also are not unique" simple-lint-error ] unless ;
137 : check-modules ( element -- )
138 \ $vocab-link swap elements [
141 "$vocab-link to non-existent vocabulary"
146 : check-rendering ( element -- )
147 [ print-content ] with-string-writer drop ;
149 : check-strings ( str -- )
152 "Paragraph text should not contain \\n or \\t"
157 "Paragraph text should not contain double spaces"
162 : check-whitespace ( str1 str2 -- )
163 [ " " tail? ] [ " " head? ] bi* or
164 [ "Missing whitespace between strings" simple-lint-error ] unless ;
166 : check-bogus-nl ( element -- )
167 { { $nl } { { $nl } } } [ head? ] with any? [
168 "Simple element should not begin with a paragraph break"
172 : extract-slots ( elements -- seq )
173 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
176 : check-class-description ( word element -- )
177 \ $class-description swap elements over class? [
179 dup struct-class? [ struct-slots ] [ all-slots ] if
181 ] [ extract-slots ] bi*
182 [ swap member? ] with reject [
183 ", " join "Described $slot does not exist: " prepend
188 "A word that is not a class has a $class-description"
193 : check-article-title ( article -- )
194 article-title first LETTER?
195 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
197 : check-elements ( element -- )
200 [ [ string? ] filter [ check-strings ] each ]
201 [ [ simple-element? ] filter [ check-elements ] each ]
202 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
205 : check-descriptions ( element -- )
206 { $description $class-description $var-description }
209 rest { { } { "" } } member?
210 [ "Empty $description" simple-lint-error ] when
214 : check-markup ( element -- )
220 [ check-descriptions ]
223 : files>vocabs ( -- assoc )
225 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
226 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
229 : group-articles ( -- assoc )
235 [ first _ at _ push-at ] [ 2drop ] if
239 : all-word-help ( words -- seq )
240 [ word-help ] filter ;