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 namespaces parser.notes
8 prettyprint sequences sequences.deep sets splitting strings
9 summary tools.destructors unicode vocabs vocabs.loader words
10 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 length [
54 "%d disposable(s) leaked in example" sprintf simple-lint-error
57 : check-examples ( element -- )
58 \ $example swap elements [ check-example ] each ;
60 : extract-values ( element -- seq )
61 \ $values swap elements
62 [ f ] [ first rest keys ] if-empty ;
64 : extract-value-effects ( element -- seq )
65 \ $values swap elements [ f ] [
67 \ $quotation swap elements [ f ] [
68 first second dup effect? [ effect>string ] when
73 : effect-values ( word -- seq )
75 [ in>> ] [ out>> ] bi append
76 [ dup pair? [ first ] when effect>string ] map members ;
78 : effect-effects ( word -- seq )
81 [ second dup effect? [ effect>string ] [ drop f ] if ]
85 : contains-funky-elements? ( element -- ? )
93 } swap '[ _ elements empty? not ] any? ;
95 : don't-check-word? ( word -- ? )
100 [ "declared-effect" word-prop not ]
102 [ "help" word-prop not ]
105 : skip-check-values? ( word element -- ? )
106 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
108 : check-values ( word element -- )
109 2dup skip-check-values? [ 2drop ] [
110 [ effect-values ] [ extract-values ] bi* 2dup
111 sequence= [ 2drop ] [
112 "$values don't match stack effect; expected %u, got %u" sprintf
117 : check-value-effects ( word element -- )
118 [ effect-effects ] [ extract-value-effects ] bi*
119 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
120 "$quotation stack effects in $values don't match"
124 : check-nulls ( element -- )
125 \ $values swap elements
126 null swap deep-member?
127 [ "$values should not contain null" simple-lint-error ] when ;
129 : check-see-also ( element -- )
130 \ $see-also swap elements [ rest all-unique? ] all?
131 [ "$see-also are not unique" simple-lint-error ] unless ;
133 : check-modules ( element -- )
134 \ $vocab-link swap elements [
137 "$vocab-link to non-existent vocabulary"
142 : check-rendering ( element -- )
143 [ print-content ] with-string-writer drop ;
145 : check-strings ( str -- )
148 "Paragraph text should not contain \\n or \\t"
153 "Paragraph text should not contain double spaces"
158 : check-whitespace ( str1 str2 -- )
159 [ " " tail? ] [ " " head? ] bi* or
160 [ "Missing whitespace between strings" simple-lint-error ] unless ;
162 : check-bogus-nl ( element -- )
163 { { $nl } { { $nl } } } [ head? ] with any? [
164 "Simple element should not begin with a paragraph break"
168 : extract-slots ( elements -- seq )
169 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
172 : check-class-description ( word element -- )
173 \ $class-description swap elements over class? [
175 dup struct-class? [ struct-slots ] [ all-slots ] if
177 ] [ extract-slots ] bi*
178 [ swap member? ] with reject [
179 ", " join "Described $slot does not exist: " prepend
184 "A word that is not a class has a $class-description"
189 : check-article-title ( article -- )
190 article-title first LETTER?
191 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
193 : check-elements ( element -- )
196 [ [ string? ] filter [ check-strings ] each ]
197 [ [ simple-element? ] filter [ check-elements ] each ]
198 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
201 : check-descriptions ( element -- )
202 { $description $class-description $var-description }
205 rest { { } { "" } } member?
206 [ "Empty $description" simple-lint-error ] when
210 : check-markup ( element -- )
216 [ check-descriptions ]
219 : files>vocabs ( -- assoc )
221 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
222 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
225 : group-articles ( -- assoc )
231 [ first _ at _ push-at ] [ 2drop ] if
235 : all-word-help ( words -- seq )
236 [ word-help ] filter ;