1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.tuple combinators
4 combinators.short-circuit debugger definitions effects eval
5 formatting fry grouping help help.markup help.topics io
6 io.streams.string kernel macros namespaces sequences
7 sequences.deep sets splitting strings summary unicode.categories
8 vocabs vocabs.loader words words.constant words.symbol ;
9 FROM: sets => members ;
12 ERROR: simple-lint-error message ;
14 M: simple-lint-error summary message>> ;
16 M: simple-lint-error error. summary print ;
20 SYMBOL: vocab-articles
22 : check-example ( element -- )
27 [ (eval>string) ] call( code -- output )
31 ] vocabs-quot get call( quot -- ) ;
32 ! ] leaks members length [
33 ! "%d disposable(s) leaked in example" sprintf simple-lint-error
36 : check-examples ( element -- )
37 \ $example swap elements [ check-example ] each ;
39 : extract-values ( element -- seq )
40 \ $values swap elements
41 [ f ] [ first rest keys ] if-empty ;
43 : extract-value-effects ( element -- seq )
44 \ $values swap elements [ f ] [
46 \ $quotation swap elements [ f ] [
47 first second dup effect? [ effect>string ] when
52 : effect-values ( word -- seq )
54 [ in>> ] [ out>> ] bi append
55 [ dup pair? [ first ] when effect>string ] map members ;
57 : effect-effects ( word -- seq )
60 [ second dup effect? [ effect>string ] [ drop f ] if ]
64 : contains-funky-elements? ( element -- ? )
72 } swap '[ _ elements empty? not ] any? ;
74 : don't-check-word? ( word -- ? )
79 [ "declared-effect" word-prop not ]
83 : skip-check-values? ( word element -- ? )
84 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
86 : check-values ( word element -- )
87 2dup skip-check-values? [ 2drop ] [
88 [ effect-values ] [ extract-values ] bi* 2dup
90 "$values don't match stack effect; expected %u, got %u" sprintf
95 : check-value-effects ( word element -- )
96 [ effect-effects ] [ extract-value-effects ] bi*
97 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
98 "$quotation stack effects in $values don't match"
102 : check-nulls ( element -- )
103 \ $values swap elements
104 null swap deep-member?
105 [ "$values should not contain null" simple-lint-error ] when ;
107 : check-see-also ( element -- )
108 \ $see-also swap elements [ rest all-unique? ] all?
109 [ "$see-also are not unique" simple-lint-error ] unless ;
111 : vocab-exists? ( name -- ? )
112 [ lookup-vocab ] [ all-vocabs get member? ] bi or ;
114 : check-modules ( element -- )
115 \ $vocab-link swap elements [
118 "$vocab-link to non-existent vocabulary"
123 : check-rendering ( element -- )
124 [ print-content ] with-string-writer drop ;
126 : check-strings ( str -- )
129 "Paragraph text should not contain \\n or \\t"
134 "Paragraph text should not contain double spaces"
139 : check-whitespace ( str1 str2 -- )
140 [ " " tail? ] [ " " head? ] bi* or
141 [ "Missing whitespace between strings" simple-lint-error ] unless ;
143 : check-bogus-nl ( element -- )
144 { { $nl } { { $nl } } } [ head? ] with any? [
145 "Simple element should not begin with a paragraph break"
149 : extract-slots ( elements -- seq )
150 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
153 : check-class-description ( word element -- )
154 \ $class-description swap elements over class? [
155 [ all-slots [ name>> ] map ] [ extract-slots ] bi*
156 [ swap member? not ] with filter [
157 ", " join "Described $slot does not exist: " prepend
162 "A word that is not a class has a $class-description"
167 : check-article-title ( article -- )
168 article-title first LETTER?
169 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
171 : check-elements ( element -- )
174 [ [ string? ] filter [ check-strings ] each ]
175 [ [ simple-element? ] filter [ check-elements ] each ]
176 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
179 : check-descriptions ( element -- )
180 { $description $class-description $var-description }
183 rest { { } { "" } } member?
184 [ "Empty $description" simple-lint-error ] when
188 : check-markup ( element -- )
194 [ check-descriptions ]
197 : files>vocabs ( -- assoc )
199 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
200 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
203 : group-articles ( -- assoc )
209 [ first _ at _ push-at ] [ 2drop ] if
213 : all-word-help ( words -- seq )
214 [ word-help ] filter ;