1 ! Copyright (C) 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces splitting sequences io.files kernel assocs
4 words vocabs vocabs.loader definitions parser continuations
5 inspector debugger io io.styles io.streams.lines hashtables
6 sorting prettyprint source-files arrays combinators strings
7 system math.parser help.markup help.topics help.syntax
11 : vocab-summary-path ( vocab -- string )
12 vocab-dir "summary.txt" path+ ;
14 : vocab-summary ( vocab -- summary )
15 dup dup vocab-summary-path vocab-file-contents
17 drop vocab-name " vocabulary" append
26 vocab-words assoc-size #
30 M: vocab-link summary vocab-summary ;
32 : set-vocab-summary ( string vocab -- )
34 dup vocab-summary-path
35 set-vocab-file-contents ;
37 : vocab-tags-path ( vocab -- string )
38 vocab-dir "tags.txt" path+ ;
40 : vocab-tags ( vocab -- tags )
41 dup vocab-tags-path vocab-file-contents ;
43 : set-vocab-tags ( tags vocab -- )
44 dup vocab-tags-path set-vocab-file-contents ;
46 : add-vocab-tags ( tags vocab -- )
47 [ vocab-tags append prune ] keep set-vocab-tags ;
49 : vocab-authors-path ( vocab -- string )
50 vocab-dir "authors.txt" path+ ;
52 : vocab-authors ( vocab -- authors )
53 dup vocab-authors-path vocab-file-contents ;
55 : set-vocab-authors ( authors vocab -- )
56 dup vocab-authors-path set-vocab-file-contents ;
58 : vocab-dir? ( root name -- ? )
60 vocab-source path+ ?resource-path exists?
65 : subdirs ( dir -- dirs )
66 directory [ second ] subset keys natural-sort ;
68 : (all-child-vocabs) ( root name -- vocabs )
69 [ vocab-dir path+ ?resource-path subdirs ] keep
73 swap [ "." swap 3append ] curry* map
76 : vocabs-in-dir ( root name -- )
77 dupd (all-child-vocabs) [
78 2dup vocab-dir? [ 2dup swap >vocab-link , ] when
82 : sane-vocab-roots "." vocab-roots get remove ;
84 : all-vocabs ( -- assoc )
86 dup [ "" vocabs-in-dir ] { } make
89 : all-vocabs-seq ( -- seq )
90 all-vocabs values concat ;
92 : dangerous? ( name -- ? )
95 { [ "cpu." ?head ] [ t ] }
96 { [ "io.unix" ?head ] [ t ] }
97 { [ "io.windows" ?head ] [ t ] }
98 { [ "ui.x11" ?head ] [ t ] }
99 { [ "ui.windows" ?head ] [ t ] }
100 { [ "ui.cocoa" ?head ] [ t ] }
101 { [ "cocoa" ?head ] [ t ] }
102 { [ "vocabs.loader.test" ?head ] [ t ] }
103 { [ "editors." ?head ] [ t ] }
104 { [ ".windows" ?tail ] [ t ] }
105 { [ ".unix" ?tail ] [ t ] }
106 { [ "unix." ?head ] [ t ] }
107 { [ ".linux" ?tail ] [ t ] }
108 { [ ".bsd" ?tail ] [ t ] }
109 { [ ".macosx" ?tail ] [ t ] }
110 { [ "windows." ?head ] [ t ] }
111 { [ "cocoa" ?head ] [ t ] }
112 { [ ".test" ?tail ] [ t ] }
113 { [ dup "tools.deploy.app" = ] [ t ] }
117 : load-everything ( -- )
119 [ vocab-name dangerous? not ] subset
120 [ [ require ] each ] no-parse-hook ;
122 : unrooted-child-vocabs ( prefix -- seq )
123 dup empty? [ CHAR: . add ] unless
125 [ vocab-root not ] subset
127 vocab-name swap ?head CHAR: . rot member? not and
131 : all-child-vocabs ( prefix -- assoc )
133 dup pick dupd (all-child-vocabs)
134 [ swap >vocab-link ] curry* map
136 f rot unrooted-child-vocabs 2array add ;
138 : load-children ( prefix -- )
139 all-child-vocabs values concat
140 [ [ require ] each ] no-parse-hook ;
142 : vocab-status-string ( vocab -- string )
144 { [ dup not ] [ drop "" ] }
145 { [ dup vocab-main ] [ drop "[Runnable]" ] }
146 { [ t ] [ drop "[Loaded]" ] }
149 : write-status ( vocab -- )
150 vocab vocab-status-string write ;
152 : vocab. ( vocab -- )
154 dup [ write-status ] with-cell
155 dup [ ($link) ] with-cell
156 [ vocab-summary write ] with-cell
159 : vocab-headings. ( -- )
161 [ "State" write ] with-cell
162 [ "Vocabulary" write ] with-cell
163 [ "Summary" write ] with-cell
166 : root-heading. ( root -- )
167 [ "Children from " swap append ] [ "Children" ] if*
170 : vocabs. ( assoc -- )
176 standard-table-style [
177 vocab-headings. [ vocab. ] each
182 : describe-summary ( vocab -- )
184 "Summary" $heading print-element
187 TUPLE: vocab-tag name ;
189 C: <vocab-tag> vocab-tag
191 : tags. ( seq -- ) [ <vocab-tag> ] map $links ;
193 : describe-tags ( vocab -- )
195 "Tags" $heading tags.
198 TUPLE: vocab-author name ;
200 C: <vocab-author> vocab-author
202 : authors. ( seq -- ) [ <vocab-author> ] map $links ;
204 : describe-authors ( vocab -- )
205 vocab-authors f like [
206 "Authors" $heading authors.
209 : describe-help ( vocab -- )
211 "Documentation" $heading nl ($link)
214 : describe-children ( vocab -- )
215 vocab-name all-child-vocabs vocabs. ;
217 : describe-files ( vocab -- )
218 vocab-files [ <pathname> ] map [
229 : describe-words ( vocab -- )
232 dup natural-sort $links
235 : map>set ( seq quot -- )
236 map concat prune natural-sort ; inline
238 : vocab-xref ( vocab quot -- vocabs )
239 >r dup vocab-name swap words r> map
240 [ [ word? ] subset [ word-vocabulary ] map ] map>set
241 remove [ vocab ] map ; inline
243 : vocab-uses ( vocab -- vocabs ) [ uses ] vocab-xref ;
245 : vocab-usage ( vocab -- vocabs ) [ usage ] vocab-xref ;
247 : describe-uses ( vocab -- )
248 vocab-uses dup empty? [
253 : describe-usage ( vocab -- )
254 vocab-usage dup empty? [
259 : $describe-vocab ( element -- )
261 dup describe-children
262 dup vocab-root over vocab-dir? [
275 : keyed-vocabs ( str quot -- seq )
278 [ >r 2dup r> swap call member? ] subset
280 ] assoc-map 2nip ; inline
282 : tagged ( tag -- assoc )
283 [ vocab-tags ] keyed-vocabs ;
285 : authored ( author -- assoc )
286 [ vocab-authors ] keyed-vocabs ;
288 : $tagged-vocabs ( element -- )
289 first tagged vocabs. ;
291 : all-tags ( vocabs -- seq ) [ vocab-tags ] map>set ;
293 : $authored-vocabs ( element -- )
294 first authored vocabs. ;
296 : all-authors ( vocabs -- seq ) [ vocab-authors ] map>set ;
298 : $tags,authors ( element -- )
304 all-authors authors. ;
306 ARTICLE: "vocab-index" "Vocabulary index"
308 { $describe-vocab "" } ;
310 M: vocab-spec article-title vocab-name " vocabulary" append ;
312 M: vocab-spec article-name vocab-name ;
314 M: vocab-spec article-content
315 vocab-name \ $describe-vocab swap 2array ;
317 M: vocab-spec article-parent drop "vocab-index" ;
321 M: vocab-tag article-title
322 vocab-tag-name "Vocabularies tagged ``" swap "''" 3append ;
324 M: vocab-tag article-name vocab-tag-name ;
326 M: vocab-tag article-content
327 \ $tagged-vocabs swap vocab-tag-name 2array ;
329 M: vocab-tag article-parent drop "vocab-index" ;
331 M: vocab-tag summary article-title ;
333 M: vocab-author >link ;
335 M: vocab-author article-title
336 vocab-author-name "Vocabularies by " swap append ;
338 M: vocab-author article-name vocab-author-name ;
340 M: vocab-author article-content
341 \ $authored-vocabs swap vocab-author-name 2array ;
343 M: vocab-author article-parent drop "vocab-index" ;
345 M: vocab-author summary article-title ;