1 ! Copyright (C) 2007, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.builtin
4 classes.intersection classes.mixin classes.predicate
5 classes.singleton classes.tuple classes.union combinators
6 effects generic help help.markup help.stylesheet help.topics io
7 io.pathnames io.styles kernel macros make namespaces sequences
8 sorting splitting summary vocabs vocabs.files vocabs.hierarchy
9 vocabs.loader vocabs.metadata words words.symbol ;
13 [ require ] [ lookup-vocab help ] bi ;
15 : vocab-row ( vocab -- row )
16 [ <$pretty-link> ] [ vocab-summary ] bi 2array ;
18 : vocab-headings ( -- headings )
20 { $strong "Vocabulary" }
24 : root-heading ( root -- )
25 [ "Children from " prepend ] [ "Children" ] if*
29 : convert-prefixes ( seq -- seq' )
30 [ dup vocab-prefix? [ name>> <vocab-link> ] when ] map ;
34 convert-prefixes [ vocab-row ] map vocab-headings prefix $table ;
36 : $vocab-roots ( assoc -- )
38 [ drop ] [ [ root-heading ] [ $vocabs ] bi* ] if-empty
41 TUPLE: vocab-tag name ;
43 INSTANCE: vocab-tag topic
45 C: <vocab-tag> vocab-tag
47 : $tags ( seq -- ) [ <vocab-tag> ] map $links ;
49 TUPLE: vocab-author name ;
51 INSTANCE: vocab-author topic
53 C: <vocab-author> vocab-author
55 : $authors ( seq -- ) [ <vocab-author> ] map $links ;
57 : describe-help ( vocab -- )
60 [ "Documentation" $heading ($link) ]
61 [ "Summary" $heading vocab-summary print-element ]
65 : describe-children ( vocab -- )
66 vocab-name disk-vocabs-for-prefix
72 [ nl ] [ [ string>> ] keep write-object ] interleave
76 : describe-files ( vocab -- )
77 vocab-files [ <pathname> ] map [
84 : describe-metadata-files ( vocab -- )
85 vocab-metadata-files [ <pathname> ] map [
86 "Metadata files" $heading
92 : describe-tuple-classes ( classes -- )
94 "Tuple classes" $subheading
97 [ superclass-of <$pretty-link> ]
98 [ "slots" word-prop [ name>> ] map unwords <$snippet> ]
101 { { $strong "Class" } { $strong "Superclass" } { $strong "Slots" } } prefix
105 : describe-predicate-classes ( classes -- )
107 "Predicate classes" $subheading
110 [ superclass-of <$pretty-link> ]
113 { { $strong "Class" } { $strong "Superclass" } } prefix
117 : (describe-classes) ( classes heading -- )
120 [ <$pretty-link> 1array ] map $table
123 : describe-builtin-classes ( classes -- )
124 "Builtin classes" (describe-classes) ;
126 : describe-singleton-classes ( classes -- )
127 "Singleton classes" (describe-classes) ;
129 : describe-mixin-classes ( classes -- )
130 "Mixin classes" (describe-classes) ;
132 : describe-union-classes ( classes -- )
133 "Union classes" (describe-classes) ;
135 : describe-intersection-classes ( classes -- )
136 "Intersection classes" (describe-classes) ;
138 : describe-classes ( classes -- )
139 [ builtin-class? ] partition
140 [ tuple-class? ] partition
141 [ singleton-class? ] partition
142 [ predicate-class? ] partition
143 [ mixin-class? ] partition
144 [ union-class? ] partition
145 [ intersection-class? ] filter
147 [ describe-builtin-classes ]
148 [ describe-tuple-classes ]
149 [ describe-singleton-classes ]
150 [ describe-predicate-classes ]
151 [ describe-mixin-classes ]
152 [ describe-union-classes ]
153 [ describe-intersection-classes ]
156 : word-syntax ( word -- string/f )
157 \ $syntax swap word-help elements dup length 1 =
158 [ first second ] [ drop f ] if ;
160 : describe-parsing ( words -- )
162 "Parsing words" $subheading
165 [ word-syntax dup [ <$snippet> ] when ]
168 { { $strong "Word" } { $strong "Syntax" } } prefix
172 : word-row ( word -- element )
174 [ stack-effect dup [ effect>string <$snippet> ] when ]
177 : word-headings ( -- element )
178 { { $strong "Word" } { $strong "Stack effect" } } ;
180 : words-table ( words -- )
181 [ word-row ] map word-headings prefix $table ;
183 : (describe-words) ( words heading -- )
184 '[ _ $subheading words-table ] unless-empty ;
186 : describe-generics ( words -- )
187 "Generic words" (describe-words) ;
189 : describe-macros ( words -- )
190 "Macro words" (describe-words) ;
192 : describe-primitives ( words -- )
193 "Primitives" (describe-words) ;
195 : describe-compounds ( words -- )
196 "Ordinary words" (describe-words) ;
198 : describe-predicates ( words -- )
199 "Class predicate words" (describe-words) ;
201 : describe-symbols ( words -- )
203 "Symbol words" $subheading
204 [ <$pretty-link> 1array ] map $table
207 : $words ( words -- )
212 [ [ class? ] filter describe-classes ]
214 [ [ class? ] [ symbol? ] bi and ] reject
215 [ parsing-word? ] partition
216 [ generic? ] partition
218 [ symbol? ] partition
219 [ primitive? ] partition
220 [ predicate? ] partition swap
223 [ describe-generics ]
226 [ describe-primitives ]
227 [ describe-compounds ]
228 [ describe-predicates ]
233 : vocab-is-not-loaded ( vocab -- )
234 "Not loaded" $heading
235 "You must first load this vocabulary to browse its documentation and words."
236 print-element vocab-name "USE: " prepend 1array $code ;
238 : describe-words ( vocab -- )
240 { [ dup lookup-vocab ] [ vocab-words $words ] }
241 { [ dup find-vocab-root ] [ vocab-is-not-loaded ] }
245 : words. ( vocab -- )
247 [ require ] [ vocab-words $words ] bi nl ;
249 : describe-metadata ( vocab -- )
251 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
252 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
253 [ vocab-platforms [ "Platforms:" swap \ $links prefix 2array , ] unless-empty ]
256 [ "Metadata" $heading $table ] unless-empty ;
258 : $vocab ( element -- )
261 [ describe-metadata ]
264 [ describe-metadata-files ]
265 [ describe-children ]
268 : keyed-vocabs ( str quot -- seq )
269 [ all-disk-vocabs-recursive ] 2dip '[
270 [ _ swap @ member? ] filter no-prefixes
274 : tagged ( tag -- assoc )
275 [ vocab-tags ] keyed-vocabs ;
277 : authored ( author -- assoc )
278 [ vocab-authors ] keyed-vocabs ;
280 : $tagged-vocabs ( element -- )
281 first tagged $vocab-roots ;
283 : $authored-vocabs ( element -- )
284 first authored $vocab-roots ;
286 : $all-tags ( element -- )
287 drop "Tags" $heading all-tags $tags ;
289 : $all-authors ( element -- )
290 drop "Authors" $heading all-authors $authors ;
292 INSTANCE: vocab topic
294 INSTANCE: vocab-link topic
296 M: vocab-spec valid-article? drop t ;
298 M: vocab-spec article-title vocab-name " vocabulary" append ;
300 M: vocab-spec article-name vocab-name ;
302 M: vocab-spec article-content
303 vocab-name \ $vocab swap 2array ;
305 M: vocab-spec article-parent drop "vocab-index" ;
309 M: vocab-tag valid-article? drop t ;
311 M: vocab-tag article-title
312 name>> "Vocabularies tagged “" "”" surround ;
314 M: vocab-tag article-name name>> ;
316 M: vocab-tag article-content
317 \ $tagged-vocabs swap name>> 2array ;
319 M: vocab-tag article-parent drop "vocab-tags" ;
321 M: vocab-tag summary article-title ;
323 M: vocab-author >link ;
325 M: vocab-author valid-article? drop t ;
327 M: vocab-author article-title
328 name>> "Vocabularies by " prepend ;
330 M: vocab-author article-name name>> ;
332 M: vocab-author article-content
333 \ $authored-vocabs swap name>> 2array ;
335 M: vocab-author article-parent drop "vocab-authors" ;
337 M: vocab-author summary article-title ;