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 : effect-values ( word -- seq )
42 [ in>> ] [ out>> ] bi append
43 [ dup pair? [ first ] when effect>string ] map members ;
45 : contains-funky-elements? ( element -- ? )
53 } swap '[ _ elements empty? not ] any? ;
55 : don't-check-word? ( word -- ? )
61 [ "declared-effect" word-prop not ]
64 : check-values ( word element -- )
68 [ contains-funky-elements? ]
75 } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
77 : check-nulls ( element -- )
78 \ $values swap elements
79 null swap deep-member?
80 [ "$values should not contain null" simple-lint-error ] when ;
82 : check-see-also ( element -- )
83 \ $see-also swap elements [
84 rest all-unique? t assert=
87 : vocab-exists? ( name -- ? )
88 [ vocab ] [ all-vocabs get member? ] bi or ;
90 : check-modules ( element -- )
91 \ $vocab-link swap elements [
94 "$vocab-link to non-existent vocabulary"
99 : check-rendering ( element -- )
100 [ print-content ] with-string-writer drop ;
102 : check-strings ( str -- )
105 "Paragraph text should not contain \\n or \\t"
110 "Paragraph text should not contain double spaces"
115 : check-whitespace ( str1 str2 -- )
116 [ " " tail? ] [ " " head? ] bi* or
117 [ "Missing whitespace between strings" simple-lint-error ] unless ;
119 : check-bogus-nl ( element -- )
120 { { $nl } { { $nl } } } [ head? ] with any? [
121 "Simple element should not begin with a paragraph break"
125 : check-class-description ( word element -- )
127 [ { $class-description } swap elements empty? not ] bi* and
128 [ "A word that is not a class has a $class-description" simple-lint-error ] when ;
130 : check-article-title ( article -- )
131 article-title first LETTER?
132 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
134 : check-elements ( element -- )
137 [ [ string? ] filter [ check-strings ] each ]
138 [ [ simple-element? ] filter [ check-elements ] each ]
139 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
142 : check-descriptions ( element -- )
143 { $description $class-description $var-description }
146 rest { { } { "" } } member?
147 [ "Empty $description" simple-lint-error ] when
151 : check-markup ( element -- )
157 [ check-descriptions ]
160 : files>vocabs ( -- assoc )
162 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
163 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
166 : group-articles ( -- assoc )
172 [ first _ at _ push-at ] [ 2drop ] if
176 : all-word-help ( words -- seq )
177 [ word-help ] filter ;