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 fry generic help help.markup help.stylesheet
7 help.topics io io.pathnames io.styles kernel macros make
8 namespaces sequences sorting summary vocabs vocabs.files
9 vocabs.hierarchy vocabs.loader vocabs.metadata words
14 [ require ] [ lookup-vocab help ] bi ;
16 : vocab-row ( vocab -- row )
17 [ <$pretty-link> ] [ vocab-summary ] bi 2array ;
19 : vocab-headings ( -- headings )
21 { $strong "Vocabulary" }
25 : root-heading ( root -- )
26 [ "Children from " prepend ] [ "Children" ] if*
30 : convert-prefixes ( seq -- seq' )
31 [ dup vocab-prefix? [ name>> <vocab-link> ] when ] map ;
35 convert-prefixes [ vocab-row ] map vocab-headings prefix $table ;
37 : $vocab-roots ( assoc -- )
39 [ drop ] [ [ root-heading ] [ $vocabs ] bi* ] if-empty
42 TUPLE: vocab-tag name ;
44 INSTANCE: vocab-tag topic
46 C: <vocab-tag> vocab-tag
48 : $tags ( seq -- ) [ <vocab-tag> ] map $links ;
50 TUPLE: vocab-author name ;
52 INSTANCE: vocab-author topic
54 C: <vocab-author> vocab-author
56 : $authors ( seq -- ) [ <vocab-author> ] map $links ;
58 : describe-help ( vocab -- )
61 [ "Documentation" $heading ($link) ]
62 [ "Summary" $heading vocab-summary print-element ]
66 : describe-children ( vocab -- )
67 vocab-name disk-vocabs-for-prefix
73 [ nl ] [ [ string>> ] keep write-object ] interleave
77 : describe-files ( vocab -- )
78 vocab-files [ <pathname> ] map [
85 : describe-metadata-files ( vocab -- )
86 vocab-metadata-files [ <pathname> ] map [
87 "Metadata files" $heading
93 : describe-tuple-classes ( classes -- )
95 "Tuple classes" $subheading
98 [ superclass-of <$pretty-link> ]
99 [ "slots" word-prop [ name>> ] map " " join <$snippet> ]
102 { { $strong "Class" } { $strong "Superclass" } { $strong "Slots" } } prefix
106 : describe-predicate-classes ( classes -- )
108 "Predicate classes" $subheading
111 [ superclass-of <$pretty-link> ]
114 { { $strong "Class" } { $strong "Superclass" } } prefix
118 : (describe-classes) ( classes heading -- )
121 [ <$pretty-link> 1array ] map $table
124 : describe-builtin-classes ( classes -- )
125 "Builtin classes" (describe-classes) ;
127 : describe-singleton-classes ( classes -- )
128 "Singleton classes" (describe-classes) ;
130 : describe-mixin-classes ( classes -- )
131 "Mixin classes" (describe-classes) ;
133 : describe-union-classes ( classes -- )
134 "Union classes" (describe-classes) ;
136 : describe-intersection-classes ( classes -- )
137 "Intersection classes" (describe-classes) ;
139 : describe-classes ( classes -- )
140 [ builtin-class? ] partition
141 [ tuple-class? ] partition
142 [ singleton-class? ] partition
143 [ predicate-class? ] partition
144 [ mixin-class? ] partition
145 [ union-class? ] partition
146 [ intersection-class? ] filter
148 [ describe-builtin-classes ]
149 [ describe-tuple-classes ]
150 [ describe-singleton-classes ]
151 [ describe-predicate-classes ]
152 [ describe-mixin-classes ]
153 [ describe-union-classes ]
154 [ describe-intersection-classes ]
157 : word-syntax ( word -- string/f )
158 \ $syntax swap word-help elements dup length 1 =
159 [ first second ] [ drop f ] if ;
161 : describe-parsing ( words -- )
163 "Parsing words" $subheading
166 [ word-syntax dup [ <$snippet> ] when ]
169 { { $strong "Word" } { $strong "Syntax" } } prefix
173 : word-row ( word -- element )
175 [ stack-effect dup [ effect>string <$snippet> ] when ]
178 : word-headings ( -- element )
179 { { $strong "Word" } { $strong "Stack effect" } } ;
181 : words-table ( words -- )
182 [ word-row ] map word-headings prefix $table ;
184 : (describe-words) ( words heading -- )
185 '[ _ $subheading words-table ] unless-empty ;
187 : describe-generics ( words -- )
188 "Generic words" (describe-words) ;
190 : describe-macros ( words -- )
191 "Macro words" (describe-words) ;
193 : describe-primitives ( words -- )
194 "Primitives" (describe-words) ;
196 : describe-compounds ( words -- )
197 "Ordinary words" (describe-words) ;
199 : describe-predicates ( words -- )
200 "Class predicate words" (describe-words) ;
202 : describe-symbols ( words -- )
204 "Symbol words" $subheading
205 [ <$pretty-link> 1array ] map $table
208 : $words ( words -- )
213 [ [ class? ] filter describe-classes ]
215 [ [ class? ] [ symbol? ] bi and ] reject
216 [ parsing-word? ] partition
217 [ generic? ] partition
219 [ symbol? ] partition
220 [ primitive? ] partition
221 [ predicate? ] partition swap
224 [ describe-generics ]
227 [ describe-primitives ]
228 [ describe-compounds ]
229 [ describe-predicates ]
234 : vocab-is-not-loaded ( vocab -- )
235 "Not loaded" $heading
236 "You must first load this vocabulary to browse its documentation and words."
237 print-element vocab-name "USE: " prepend 1array $code ;
239 : describe-words ( vocab -- )
241 { [ dup lookup-vocab ] [ vocab-words $words ] }
242 { [ dup find-vocab-root ] [ vocab-is-not-loaded ] }
246 : words. ( vocab -- )
248 [ require ] [ vocab-words $words ] bi nl ;
250 : describe-metadata ( vocab -- )
252 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
253 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
254 [ vocab-platforms [ "Platforms:" swap \ $links prefix 2array , ] unless-empty ]
257 [ "Metadata" $heading $table ] unless-empty ;
259 : $vocab ( element -- )
262 [ describe-metadata ]
265 [ describe-metadata-files ]
266 [ describe-children ]
269 : keyed-vocabs ( str quot -- seq )
270 [ all-disk-vocabs-recursive ] 2dip '[
271 [ _ swap @ member? ] filter no-prefixes
275 : tagged ( tag -- assoc )
276 [ vocab-tags ] keyed-vocabs ;
278 : authored ( author -- assoc )
279 [ vocab-authors ] keyed-vocabs ;
281 : $tagged-vocabs ( element -- )
282 first tagged $vocab-roots ;
284 : $authored-vocabs ( element -- )
285 first authored $vocab-roots ;
287 : $all-tags ( element -- )
288 drop "Tags" $heading all-tags $tags ;
290 : $all-authors ( element -- )
291 drop "Authors" $heading all-authors $authors ;
293 INSTANCE: vocab topic
295 INSTANCE: vocab-link topic
297 M: vocab-spec valid-article? drop t ;
299 M: vocab-spec article-title vocab-name " vocabulary" append ;
301 M: vocab-spec article-name vocab-name ;
303 M: vocab-spec article-content
304 vocab-name \ $vocab swap 2array ;
306 M: vocab-spec article-parent drop "vocab-index" ;
310 M: vocab-tag valid-article? drop t ;
312 M: vocab-tag article-title
313 name>> "Vocabularies tagged “" "”" surround ;
315 M: vocab-tag article-name name>> ;
317 M: vocab-tag article-content
318 \ $tagged-vocabs swap name>> 2array ;
320 M: vocab-tag article-parent drop "vocab-tags" ;
322 M: vocab-tag summary article-title ;
324 M: vocab-author >link ;
326 M: vocab-author valid-article? drop t ;
328 M: vocab-author article-title
329 name>> "Vocabularies by " prepend ;
331 M: vocab-author article-name name>> ;
333 M: vocab-author article-content
334 \ $authored-vocabs swap name>> 2array ;
336 M: vocab-author article-parent drop "vocab-authors" ;
338 M: vocab-author summary article-title ;