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 debugger
5 definitions effects eval formatting fry grouping help
6 help.markup help.topics io io.streams.string kernel macros math
7 namespaces sequences sequences.deep sets splitting strings
8 summary tools.destructors unicode vocabs vocabs.loader words
9 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 : check-example ( element -- )
26 [ (eval>string) ] call( code -- output )
30 ] vocabs-quot get call( quot -- )
33 "line" "single-texture" "multi-texture"
36 "%d disposable(s) leaked in example" sprintf simple-lint-error
39 : check-examples ( element -- )
40 \ $example swap elements [ check-example ] each ;
42 : extract-values ( element -- seq )
43 \ $values swap elements
44 [ f ] [ first rest keys ] if-empty ;
46 : extract-value-effects ( element -- seq )
47 \ $values swap elements [ f ] [
49 \ $quotation swap elements [ f ] [
50 first second dup effect? [ effect>string ] when
55 : effect-values ( word -- seq )
57 [ in>> ] [ out>> ] bi append
58 [ dup pair? [ first ] when effect>string ] map members ;
60 : effect-effects ( word -- seq )
63 [ second dup effect? [ effect>string ] [ drop f ] if ]
67 : contains-funky-elements? ( element -- ? )
75 } swap '[ _ elements empty? not ] any? ;
77 : don't-check-word? ( word -- ? )
82 [ "declared-effect" word-prop not ]
84 [ "word-help" word-prop not ]
87 : skip-check-values? ( word element -- ? )
88 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
90 : check-values ( word element -- )
91 2dup skip-check-values? [ 2drop ] [
92 [ effect-values ] [ extract-values ] bi* 2dup
94 "$values don't match stack effect; expected %u, got %u" sprintf
99 : check-value-effects ( word element -- )
100 [ effect-effects ] [ extract-value-effects ] bi*
101 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
102 "$quotation stack effects in $values don't match"
106 : check-nulls ( element -- )
107 \ $values swap elements
108 null swap deep-member?
109 [ "$values should not contain null" simple-lint-error ] when ;
111 : check-see-also ( element -- )
112 \ $see-also swap elements [ rest all-unique? ] all?
113 [ "$see-also are not unique" simple-lint-error ] unless ;
115 : check-modules ( element -- )
116 \ $vocab-link swap elements [
119 "$vocab-link to non-existent vocabulary"
124 : check-rendering ( element -- )
125 [ print-content ] with-string-writer drop ;
127 : check-strings ( str -- )
130 "Paragraph text should not contain \\n or \\t"
135 "Paragraph text should not contain double spaces"
140 : check-whitespace ( str1 str2 -- )
141 [ " " tail? ] [ " " head? ] bi* or
142 [ "Missing whitespace between strings" simple-lint-error ] unless ;
144 : check-bogus-nl ( element -- )
145 { { $nl } { { $nl } } } [ head? ] with any? [
146 "Simple element should not begin with a paragraph break"
150 : extract-slots ( elements -- seq )
151 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
154 : check-class-description ( word element -- )
155 \ $class-description swap elements over class? [
157 dup struct-class? [ struct-slots ] [ all-slots ] if
159 ] [ extract-slots ] bi*
160 [ swap member? ] with reject [
161 ", " join "Described $slot does not exist: " prepend
166 "A word that is not a class has a $class-description"
171 : check-article-title ( article -- )
172 article-title first LETTER?
173 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
175 : check-elements ( element -- )
178 [ [ string? ] filter [ check-strings ] each ]
179 [ [ simple-element? ] filter [ check-elements ] each ]
180 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
183 : check-descriptions ( element -- )
184 { $description $class-description $var-description }
187 rest { { } { "" } } member?
188 [ "Empty $description" simple-lint-error ] when
192 : check-markup ( element -- )
198 [ check-descriptions ]
201 : files>vocabs ( -- assoc )
203 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
204 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
207 : group-articles ( -- assoc )
213 [ first _ at _ push-at ] [ 2drop ] if
217 : all-word-help ( words -- seq )
218 [ word-help ] filter ;