1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes combinators
4 combinators.short-circuit definitions effects eval fry grouping
5 help help.markup help.topics io.streams.string kernel macros
6 namespaces sequences sequences.deep sets sorting splitting
7 strings unicode.categories values vocabs vocabs.loader words
8 words.symbol summary debugger io ;
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 -- )
26 [ (eval>string) ] call( code -- output )
30 ] vocabs-quot get call( quot -- ) ;
32 : check-examples ( element -- )
33 \ $example swap elements [ check-example ] each ;
35 : extract-values ( element -- seq )
36 \ $values swap elements dup empty? [
37 first rest [ first ] map
40 : extract-value-effects ( element -- seq )
41 \ $values swap elements dup empty? [
43 \ $quotation swap elements dup empty? [ drop f ] [
49 : effect-values ( word -- seq )
51 [ in>> ] [ out>> ] bi append
52 [ dup pair? [ first ] when effect>string ] map members ;
54 : effect-effects ( word -- seq )
57 [ second dup effect? [ effect>string ] [ drop f ] if ]
61 : contains-funky-elements? ( element -- ? )
69 } swap '[ _ elements empty? not ] any? ;
71 : don't-check-word? ( word -- ? )
77 [ "declared-effect" word-prop not ]
80 : check-values ( word element -- )
84 [ contains-funky-elements? ]
91 } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
93 : check-value-effects ( word element -- )
95 [ extract-value-effects ]
96 bi* [ 2dup and [ = ] [ 2drop t ] if ] 2all?
97 [ "$quotation documentation in $values don't match stack effect" simple-lint-error ]
100 : check-nulls ( element -- )
101 \ $values swap elements
102 null swap deep-member?
103 [ "$values should not contain null" simple-lint-error ] when ;
105 : check-see-also ( element -- )
106 \ $see-also swap elements [
107 rest all-unique? t assert=
110 : vocab-exists? ( name -- ? )
111 [ vocab ] [ all-vocabs get member? ] bi or ;
113 : check-modules ( element -- )
114 \ $vocab-link swap elements [
117 "$vocab-link to non-existent vocabulary"
122 : check-rendering ( element -- )
123 [ print-content ] with-string-writer drop ;
125 : check-strings ( str -- )
128 "Paragraph text should not contain \\n or \\t"
133 "Paragraph text should not contain double spaces"
138 : check-whitespace ( str1 str2 -- )
139 [ " " tail? ] [ " " head? ] bi* or
140 [ "Missing whitespace between strings" simple-lint-error ] unless ;
142 : check-bogus-nl ( element -- )
143 { { $nl } { { $nl } } } [ head? ] with any? [
144 "Simple element should not begin with a paragraph break"
148 : check-class-description ( word element -- )
150 [ { $class-description } swap elements empty? not ] bi* and
151 [ "A word that is not a class has a $class-description" simple-lint-error ] when ;
153 : check-article-title ( article -- )
154 article-title first LETTER?
155 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
157 : check-elements ( element -- )
160 [ [ string? ] filter [ check-strings ] each ]
161 [ [ simple-element? ] filter [ check-elements ] each ]
162 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
165 : check-descriptions ( element -- )
166 { $description $class-description $var-description }
169 rest { { } { "" } } member?
170 [ "Empty $description" simple-lint-error ] when
174 : check-markup ( element -- )
180 [ check-descriptions ]
183 : files>vocabs ( -- assoc )
185 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
186 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
189 : group-articles ( -- assoc )
195 [ first _ at _ push-at ] [ 2drop ] if
199 : all-word-help ( words -- seq )
200 [ word-help ] filter ;