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 ;
11 ERROR: simple-lint-error message ;
13 M: simple-lint-error summary message>> ;
15 M: simple-lint-error error. summary print ;
19 SYMBOL: vocab-articles
21 : check-example ( element -- )
25 [ (eval>string) ] call( code -- output )
29 ] vocabs-quot get call( quot -- ) ;
31 : check-examples ( element -- )
32 \ $example swap elements [ check-example ] each ;
34 : extract-values ( element -- seq )
35 \ $values swap elements dup empty? [
36 first rest [ first ] map
39 : extract-value-effects ( element -- seq )
40 \ $values swap elements dup empty? [
42 \ $quotation swap elements dup empty? [ drop f ] [
48 : effect-values ( word -- seq )
50 [ in>> ] [ out>> ] bi append
51 [ dup pair? [ first ] when effect>string ] map prune ;
53 : effect-effects ( word -- seq )
56 [ second dup effect? [ effect>string ] [ drop f ] if ]
60 : contains-funky-elements? ( element -- ? )
68 } swap '[ _ elements empty? not ] any? ;
70 : don't-check-word? ( word -- ? )
76 [ "declared-effect" word-prop not ]
79 : check-values ( word element -- )
83 [ contains-funky-elements? ]
90 } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
92 : check-value-effects ( word element -- )
94 [ extract-value-effects ]
95 bi* [ 2dup and [ = ] [ 2drop t ] if ] 2all?
96 [ "$quotation documentation in $values don't match stack effect" simple-lint-error ]
99 : check-nulls ( element -- )
100 \ $values swap elements
101 null swap deep-member?
102 [ "$values should not contain null" simple-lint-error ] when ;
104 : check-see-also ( element -- )
105 \ $see-also swap elements [
106 rest dup prune [ length ] bi@ assert=
109 : vocab-exists? ( name -- ? )
110 [ vocab ] [ all-vocabs get member? ] bi or ;
112 : check-modules ( element -- )
113 \ $vocab-link swap elements [
116 "$vocab-link to non-existent vocabulary"
121 : check-rendering ( element -- )
122 [ print-content ] with-string-writer drop ;
124 : check-strings ( str -- )
127 "Paragraph text should not contain \\n or \\t"
132 "Paragraph text should not contain double spaces"
137 : check-whitespace ( str1 str2 -- )
138 [ " " tail? ] [ " " head? ] bi* or
139 [ "Missing whitespace between strings" simple-lint-error ] unless ;
141 : check-bogus-nl ( element -- )
142 { { $nl } { { $nl } } } [ head? ] with any? [
143 "Simple element should not begin with a paragraph break"
147 : check-class-description ( word element -- )
149 [ { $class-description } swap elements empty? not ] bi* and
150 [ "A word that is not a class has a $class-description" simple-lint-error ] when ;
152 : check-article-title ( article -- )
153 article-title first LETTER?
154 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
156 : check-elements ( element -- )
159 [ [ string? ] filter [ check-strings ] each ]
160 [ [ simple-element? ] filter [ check-elements ] each ]
161 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
164 : check-descriptions ( element -- )
165 { $description $class-description $var-description }
168 rest { { } { "" } } member?
169 [ "Empty $description" simple-lint-error ] when
173 : check-markup ( element -- )
179 [ check-descriptions ]
182 : files>vocabs ( -- assoc )
184 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
185 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
188 : group-articles ( -- assoc )
194 [ first _ at _ push-at ] [ 2drop ] if
198 : all-word-help ( words -- seq )
199 [ word-help ] filter ;