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 natural-sort
39 : effect-values ( word -- seq )
41 [ in>> ] [ out>> ] bi append
42 [ dup pair? [ first ] when effect>string ] map
45 : contains-funky-elements? ( element -- ? )
52 } swap '[ _ elements empty? not ] any? ;
54 : don't-check-word? ( word -- ? )
60 [ "declared-effect" word-prop not ]
63 : check-values ( word element -- )
67 [ contains-funky-elements? ]
74 } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
76 : check-nulls ( element -- )
77 \ $values swap elements
78 null swap deep-member?
79 [ "$values should not contain null" simple-lint-error ] when ;
81 : check-see-also ( element -- )
82 \ $see-also swap elements [
83 rest dup prune [ length ] bi@ assert=
86 : vocab-exists? ( name -- ? )
87 [ vocab ] [ all-vocabs get member? ] bi or ;
89 : check-modules ( element -- )
90 \ $vocab-link swap elements [
93 "$vocab-link to non-existent vocabulary"
98 : check-rendering ( element -- )
99 [ print-content ] with-string-writer drop ;
101 : check-strings ( str -- )
104 "Paragraph text should not contain \\n or \\t"
109 "Paragraph text should not contain double spaces"
114 : check-whitespace ( str1 str2 -- )
115 [ " " tail? ] [ " " head? ] bi* or
116 [ "Missing whitespace between strings" simple-lint-error ] unless ;
118 : check-bogus-nl ( element -- )
119 { { $nl } { { $nl } } } [ head? ] with any? [
120 "Simple element should not begin with a paragraph break"
124 : check-class-description ( word element -- )
126 [ { $class-description } swap elements empty? not ] bi* and
127 [ "A word that is not a class has a $class-description" simple-lint-error ] when ;
129 : check-article-title ( article -- )
130 article-title first LETTER?
131 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
133 : check-elements ( element -- )
136 [ [ string? ] filter [ check-strings ] each ]
137 [ [ simple-element? ] filter [ check-elements ] each ]
138 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
141 : check-descriptions ( element -- )
142 { $description $class-description $var-description }
145 rest { { } { "" } } member?
146 [ "Empty description" throw ] when
150 : check-markup ( element -- )
156 [ check-descriptions ]
159 : files>vocabs ( -- assoc )
161 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
162 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
165 : group-articles ( -- assoc )
171 [ first _ at _ push-at ] [ 2drop ] if
175 : all-word-help ( words -- seq )
176 [ word-help ] filter ;