1 ! Copyright (C) 2006, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: sequences parser kernel help help.markup help.topics
4 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 )
30 stack-effect dup effect-in swap effect-out append [
32 { [ dup word? ] [ word-name ] }
33 { [ dup integer? ] [ drop "object" ] }
34 { [ dup string? ] [ ] }
36 ] map prune natural-sort ;
38 : contains-funky-elements? ( element -- ? )
45 } swap [ elements f like ] curry contains? ;
47 : check-values ( word element -- )
49 { [ over "declared-effect" word-prop ] [ 2drop ] }
50 { [ dup contains-funky-elements? not ] [ 2drop ] }
51 { [ over macro? not ] [ 2drop ] }
53 [ effect-values >array ]
54 [ extract-values >array ]
59 : check-see-also ( word element -- )
60 nip \ $see-also swap elements [
61 rest dup prune [ length ] bi@ assert=
64 : vocab-exists? ( name -- ? )
65 dup vocab swap "all-vocabs" get member? or ;
67 : check-modules ( word element -- )
68 nip \ $vocab-link swap elements [
70 vocab-exists? [ "Missing vocabulary" throw ] unless
73 : check-rendering ( word element -- )
74 [ help ] with-string-writer drop ;
76 : all-word-help ( words -- seq )
77 [ word-help ] filter ;
79 TUPLE: help-error topic ;
81 : <help-error> ( topic delegate -- error )
82 { set-help-error-topic set-delegate } help-error construct ;
85 "In " write dup help-error-topic ($link) nl
88 : check-something ( obj quot -- )
89 flush [ <help-error> , ] recover ; inline
91 : check-word ( word -- )
99 2dup drop check-rendering
104 : check-words ( words -- ) [ check-word ] each ;
106 : check-article ( article -- )
108 [ dup check-rendering ] assert-depth drop
111 : group-articles ( -- assoc )
113 vocabs [ dup vocab-docs-path swap ] H{ } map>assoc
116 >r >r dup >link where dup
117 [ first r> at r> push-at ]
118 [ r> r> 2drop 2drop ]
123 : check-vocab ( vocab -- seq )
124 "Checking " write dup write "..." print
126 dup words [ check-word ] each
127 "vocab-articles" get at [ check-article ] each
130 : run-help-lint ( prefix -- alist )
132 all-vocabs-seq [ vocab-name ] map "all-vocabs" set
133 articles get keys "group-articles" set
135 [ dup check-vocab ] { } map>assoc
136 [ nip empty? not ] assoc-filter
139 : typos. ( assoc -- )
142 "==== ALL CHECKS PASSED" print
150 : help-lint ( prefix -- ) run-help-lint typos. ;
152 : help-lint-all ( -- ) "" help-lint ;
154 : unlinked-words ( words -- seq )
155 all-word-help [ article-parent not ] filter ;
157 : linked-undocumented-words ( -- seq )
159 [ word-help not ] filter
160 [ article-parent ] filter
161 [ "predicating" word-prop not ] filter ;