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 debugger definitions effects eval formatting
6 fry grouping help help.markup help.topics io io.streams.string
7 kernel macros math namespaces prettyprint sequences
8 sequences.deep sets splitting strings summary tools.destructors
9 unicode vocabs vocabs.loader words words.constant words.symbol ;
12 ERROR: simple-lint-error message ;
14 M: simple-lint-error summary message>> ;
16 M: simple-lint-error error. summary print ;
19 SYMBOL: vocab-articles
21 : no-ui-disposables ( seq -- seq' )
24 "single-texture" "multi-texture" ! opengl.textures
26 "layout" ! ui.text.pango
27 "script-string" ! windows.uniscribe
31 : check-example ( element -- )
35 but-last "\n" join parse-string [
36 [ output>array [ . ] each ] call( quot -- )
41 ] vocabs-quot get call( quot -- )
42 ] leaks members no-ui-disposables length [
43 "%d disposable(s) leaked in example" sprintf simple-lint-error
46 : check-examples ( element -- )
47 \ $example swap elements [ check-example ] each ;
49 : extract-values ( element -- seq )
50 \ $values swap elements
51 [ f ] [ first rest keys ] if-empty ;
53 : extract-value-effects ( element -- seq )
54 \ $values swap elements [ f ] [
56 \ $quotation swap elements [ f ] [
57 first second dup effect? [ effect>string ] when
62 : effect-values ( word -- seq )
64 [ in>> ] [ out>> ] bi append
65 [ dup pair? [ first ] when effect>string ] map members ;
67 : effect-effects ( word -- seq )
70 [ second dup effect? [ effect>string ] [ drop f ] if ]
74 : contains-funky-elements? ( element -- ? )
82 } swap '[ _ elements empty? not ] any? ;
84 : don't-check-word? ( word -- ? )
89 [ "declared-effect" word-prop not ]
91 [ "word-help" word-prop not ]
94 : skip-check-values? ( word element -- ? )
95 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
97 : check-values ( word element -- )
98 2dup skip-check-values? [ 2drop ] [
99 [ effect-values ] [ extract-values ] bi* 2dup
100 sequence= [ 2drop ] [
101 "$values don't match stack effect; expected %u, got %u" sprintf
106 : check-value-effects ( word element -- )
107 [ effect-effects ] [ extract-value-effects ] bi*
108 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
109 "$quotation stack effects in $values don't match"
113 : check-nulls ( element -- )
114 \ $values swap elements
115 null swap deep-member?
116 [ "$values should not contain null" simple-lint-error ] when ;
118 : check-see-also ( element -- )
119 \ $see-also swap elements [ rest all-unique? ] all?
120 [ "$see-also are not unique" simple-lint-error ] unless ;
122 : check-modules ( element -- )
123 \ $vocab-link swap elements [
126 "$vocab-link to non-existent vocabulary"
131 : check-rendering ( element -- )
132 [ print-content ] with-string-writer drop ;
134 : check-strings ( str -- )
137 "Paragraph text should not contain \\n or \\t"
142 "Paragraph text should not contain double spaces"
147 : check-whitespace ( str1 str2 -- )
148 [ " " tail? ] [ " " head? ] bi* or
149 [ "Missing whitespace between strings" simple-lint-error ] unless ;
151 : check-bogus-nl ( element -- )
152 { { $nl } { { $nl } } } [ head? ] with any? [
153 "Simple element should not begin with a paragraph break"
157 : extract-slots ( elements -- seq )
158 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
161 : check-class-description ( word element -- )
162 \ $class-description swap elements over class? [
164 dup struct-class? [ struct-slots ] [ all-slots ] if
166 ] [ extract-slots ] bi*
167 [ swap member? ] with reject [
168 ", " join "Described $slot does not exist: " prepend
173 "A word that is not a class has a $class-description"
178 : check-article-title ( article -- )
179 article-title first LETTER?
180 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
182 : check-elements ( element -- )
185 [ [ string? ] filter [ check-strings ] each ]
186 [ [ simple-element? ] filter [ check-elements ] each ]
187 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
190 : check-descriptions ( element -- )
191 { $description $class-description $var-description }
194 rest { { } { "" } } member?
195 [ "Empty $description" simple-lint-error ] when
199 : check-markup ( element -- )
205 [ check-descriptions ]
208 : files>vocabs ( -- assoc )
210 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
211 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
214 : group-articles ( -- assoc )
220 [ first _ at _ push-at ] [ 2drop ] if
224 : all-word-help ( words -- seq )
225 [ word-help ] filter ;