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 -- ? )
94 } swap '[ _ elements empty? not ] any? ;
96 : don't-check-word? ( word -- ? )
101 [ "declared-effect" word-prop not ]
103 [ "word-help" word-prop not ]
106 : skip-check-values? ( word element -- ? )
107 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
109 : check-values ( word element -- )
110 2dup skip-check-values? [ 2drop ] [
111 [ effect-values ] [ extract-values ] bi* 2dup
112 sequence= [ 2drop ] [
113 "$values don't match stack effect; expected %u, got %u" sprintf
118 : check-value-effects ( word element -- )
119 [ effect-effects ] [ extract-value-effects ] bi*
120 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
121 "$quotation stack effects in $values don't match"
125 : check-nulls ( element -- )
126 \ $values swap elements
127 null swap deep-member?
128 [ "$values should not contain null" simple-lint-error ] when ;
130 : check-see-also ( element -- )
131 \ $see-also swap elements [ rest all-unique? ] all?
132 [ "$see-also are not unique" simple-lint-error ] unless ;
134 : check-modules ( element -- )
135 \ $vocab-link swap elements [
138 "$vocab-link to non-existent vocabulary"
143 : check-rendering ( element -- )
144 [ print-content ] with-string-writer drop ;
146 : check-strings ( str -- )
149 "Paragraph text should not contain \\n or \\t"
154 "Paragraph text should not contain double spaces"
159 : check-whitespace ( str1 str2 -- )
160 [ " " tail? ] [ " " head? ] bi* or
161 [ "Missing whitespace between strings" simple-lint-error ] unless ;
163 : check-bogus-nl ( element -- )
164 { { $nl } { { $nl } } } [ head? ] with any? [
165 "Simple element should not begin with a paragraph break"
169 : extract-slots ( elements -- seq )
170 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
173 : check-class-description ( word element -- )
174 \ $class-description swap elements over class? [
176 dup struct-class? [ struct-slots ] [ all-slots ] if
178 ] [ extract-slots ] bi*
179 [ swap member? ] with reject [
180 ", " join "Described $slot does not exist: " prepend
185 "A word that is not a class has a $class-description"
190 : check-article-title ( article -- )
191 article-title first LETTER?
192 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
194 : check-elements ( element -- )
197 [ [ string? ] filter [ check-strings ] each ]
198 [ [ simple-element? ] filter [ check-elements ] each ]
199 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
202 : check-descriptions ( element -- )
203 { $description $class-description $var-description }
206 rest { { } { "" } } member?
207 [ "Empty $description" simple-lint-error ] when
211 : check-markup ( element -- )
217 [ check-descriptions ]
220 : files>vocabs ( -- assoc )
222 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
223 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
226 : group-articles ( -- assoc )
232 [ first _ at _ push-at ] [ 2drop ] if
236 : all-word-help ( words -- seq )
237 [ word-help ] filter ;