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 prune
39 : effect-values ( word -- seq )
41 [ in>> ] [ out>> ] bi append
42 [ dup pair? [ first ] when effect>string ] map prune ;
44 : contains-funky-elements? ( element -- ? )
51 } swap '[ _ elements empty? not ] any? ;
53 : don't-check-word? ( word -- ? )
59 [ "declared-effect" word-prop not ]
62 : check-values ( word element -- )
66 [ contains-funky-elements? ]
73 } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
75 : check-nulls ( element -- )
76 \ $values swap elements
77 null swap deep-member?
78 [ "$values should not contain null" simple-lint-error ] when ;
80 : check-see-also ( element -- )
81 \ $see-also swap elements [
82 rest dup prune [ length ] bi@ assert=
85 : vocab-exists? ( name -- ? )
86 [ vocab ] [ all-vocabs get member? ] bi or ;
88 : check-modules ( element -- )
89 \ $vocab-link swap elements [
92 "$vocab-link to non-existent vocabulary"
97 : check-rendering ( element -- )
98 [ print-content ] with-string-writer drop ;
100 : check-strings ( str -- )
103 "Paragraph text should not contain \\n or \\t"
108 "Paragraph text should not contain double spaces"
113 : check-whitespace ( str1 str2 -- )
114 [ " " tail? ] [ " " head? ] bi* or
115 [ "Missing whitespace between strings" simple-lint-error ] unless ;
117 : check-bogus-nl ( element -- )
118 { { $nl } { { $nl } } } [ head? ] with any? [
119 "Simple element should not begin with a paragraph break"
123 : check-class-description ( word element -- )
125 [ { $class-description } swap elements empty? not ] bi* and
126 [ "A word that is not a class has a $class-description" simple-lint-error ] when ;
128 : check-article-title ( article -- )
129 article-title first LETTER?
130 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
132 : check-elements ( element -- )
135 [ [ string? ] filter [ check-strings ] each ]
136 [ [ simple-element? ] filter [ check-elements ] each ]
137 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
140 : check-descriptions ( element -- )
141 { $description $class-description $var-description }
144 rest { { } { "" } } member?
145 [ "Empty $description" simple-lint-error ] when
149 : check-markup ( element -- )
155 [ check-descriptions ]
158 : files>vocabs ( -- assoc )
160 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
161 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
164 : group-articles ( -- assoc )
170 [ first _ at _ push-at ] [ 2drop ] if
174 : all-word-help ( words -- seq )
175 [ word-help ] filter ;