1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors sequences parser kernel help help.markup
4 help.topics words strings classes tools.vocabs namespaces io
5 io.streams.string prettyprint definitions arrays vectors
6 combinators splitting debugger hashtables sorting effects vocabs
7 vocabs.loader assocs editors continuations classes.predicate
11 : check-example ( element -- )
13 but-last "\n" join 1vector
16 [ eval>string ] with-datastack
17 ] with-scope peek "\n" ?tail drop
21 : check-examples ( word element -- )
22 nip \ $example swap elements [ check-example ] each ;
24 : extract-values ( element -- seq )
25 \ $values swap elements dup empty? [
26 first rest [ first ] map prune natural-sort
29 : effect-values ( word -- seq )
31 [ in>> ] [ out>> ] bi append
32 [ (stack-picture) ] map
35 : contains-funky-elements? ( element -- ? )
42 } swap [ elements f like ] curry contains? ;
44 : check-values ( word element -- )
46 { [ over "declared-effect" word-prop ] [ 2drop ] }
47 { [ dup contains-funky-elements? not ] [ 2drop ] }
48 { [ over macro? not ] [ 2drop ] }
50 [ effect-values >array ]
51 [ extract-values >array ]
56 : check-see-also ( word element -- )
57 nip \ $see-also swap elements [
58 rest dup prune [ length ] bi@ assert=
61 : vocab-exists? ( name -- ? )
62 dup vocab swap "all-vocabs" get member? or ;
64 : check-modules ( word element -- )
65 nip \ $vocab-link swap elements [
67 vocab-exists? [ "Missing vocabulary" throw ] unless
70 : check-rendering ( word element -- )
71 [ help ] with-string-writer drop ;
73 : all-word-help ( words -- seq )
74 [ word-help ] filter ;
76 TUPLE: help-error topic ;
78 : <help-error> ( topic delegate -- error )
79 { set-help-error-topic set-delegate } help-error construct ;
82 "In " write dup help-error-topic ($link) nl
85 : check-something ( obj quot -- )
86 flush [ <help-error> , ] recover ; inline
88 : check-word ( word -- )
96 2dup drop check-rendering
101 : check-words ( words -- ) [ check-word ] each ;
103 : check-article ( article -- )
105 [ dup check-rendering ] assert-depth drop
108 : group-articles ( -- assoc )
110 vocabs [ dup vocab-docs-path swap ] H{ } map>assoc
113 >r >r dup >link where dup
114 [ first r> at r> push-at ]
115 [ r> r> 2drop 2drop ]
120 : check-vocab ( vocab -- seq )
121 "Checking " write dup write "..." print
123 dup words [ check-word ] each
124 "vocab-articles" get at [ check-article ] each
127 : run-help-lint ( prefix -- alist )
129 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
130 articles get keys "group-articles" set
132 [ dup check-vocab ] { } map>assoc
133 [ nip empty? not ] assoc-filter
136 : typos. ( assoc -- )
139 "==== ALL CHECKS PASSED" print
147 : help-lint ( prefix -- ) run-help-lint typos. ;
149 : help-lint-all ( -- ) "" help-lint ;
151 : unlinked-words ( words -- seq )
152 all-word-help [ article-parent not ] filter ;
154 : linked-undocumented-words ( -- seq )
156 [ word-help not ] filter
157 [ article-parent ] filter
158 [ "predicating" word-prop not ] filter ;