1 ! Copyright (C) 2007, 2008 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 definitions effects fry generic help help.markup help.stylesheet
7 help.topics io io.files io.pathnames io.styles kernel macros
8 make namespaces prettyprint sequences sets sorting summary
9 tools.vocabs vocabs vocabs.loader words words.symbol ;
10 IN: tools.vocabs.browser
12 : vocab-status-string ( vocab -- string )
14 { [ dup vocab not ] [ drop "" ] }
15 { [ dup vocab-main ] [ drop "[Runnable]" ] }
19 : vocab-row ( vocab -- row )
20 [ <$link> ] [ vocab-status-string ] [ vocab-summary ] tri
23 : vocab-headings ( -- headings )
25 { $strong "Vocabulary" }
30 : root-heading ( root -- )
31 [ "Children from " prepend ] [ "Children" ] if*
35 [ 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 all-child-vocabs $vocab-roots ;
69 : describe-files ( vocab -- )
70 vocab-files [ <pathname> ] map [
81 : describe-tuple-classes ( classes -- )
83 "Tuple classes" $subheading
86 [ superclass <$link> ]
87 [ "slots" word-prop [ name>> ] map " " join <$snippet> ]
90 { { $strong "Class" } { $strong "Superclass" } { $strong "Slots" } } prefix
94 : describe-predicate-classes ( classes -- )
96 "Predicate classes" $subheading
99 [ superclass <$link> ]
102 { { $strong "Class" } { $strong "Superclass" } } prefix
106 : (describe-classes) ( classes heading -- )
109 [ <$link> 1array ] map $table
112 : describe-builtin-classes ( classes -- )
113 "Builtin classes" (describe-classes) ;
115 : describe-singleton-classes ( classes -- )
116 "Singleton classes" (describe-classes) ;
118 : describe-mixin-classes ( classes -- )
119 "Mixin classes" (describe-classes) ;
121 : describe-union-classes ( classes -- )
122 "Union classes" (describe-classes) ;
124 : describe-intersection-classes ( classes -- )
125 "Intersection classes" (describe-classes) ;
127 : describe-classes ( classes -- )
128 [ builtin-class? ] partition
129 [ tuple-class? ] partition
130 [ singleton-class? ] partition
131 [ predicate-class? ] partition
132 [ mixin-class? ] partition
133 [ union-class? ] partition
134 [ intersection-class? ] filter
136 [ describe-builtin-classes ]
137 [ describe-tuple-classes ]
138 [ describe-singleton-classes ]
139 [ describe-predicate-classes ]
140 [ describe-mixin-classes ]
141 [ describe-union-classes ]
142 [ describe-intersection-classes ]
145 : word-syntax ( word -- string/f )
146 \ $syntax swap word-help elements dup length 1 =
147 [ first second ] [ drop f ] if ;
149 : describe-parsing ( words -- )
151 "Parsing words" $subheading
154 [ word-syntax dup [ <$snippet> ] when ]
157 { { $strong "Word" } { $strong "Syntax" } } prefix
161 : words-table ( words -- )
164 [ stack-effect dup [ effect>string <$snippet> ] when ]
167 { { $strong "Word" } { $strong "Stack effect" } } prefix
170 : (describe-words) ( words heading -- )
171 '[ _ $subheading words-table ] unless-empty ;
173 : describe-generics ( words -- )
174 "Generic words" (describe-words) ;
176 : describe-macros ( words -- )
177 "Macro words" (describe-words) ;
179 : describe-primitives ( words -- )
180 "Primitives" (describe-words) ;
182 : describe-compounds ( words -- )
183 "Ordinary words" (describe-words) ;
185 : describe-predicates ( words -- )
186 "Class predicate words" (describe-words) ;
188 : describe-symbols ( words -- )
190 "Symbol words" $subheading
191 [ <$link> 1array ] map $table
194 : $words ( words -- )
199 [ [ class? ] filter describe-classes ]
201 [ [ class? ] [ symbol? ] bi and not ] filter
202 [ parsing-word? ] partition
203 [ generic? ] partition
205 [ symbol? ] partition
206 [ primitive? ] partition
207 [ predicate? ] partition swap
210 [ describe-generics ]
213 [ describe-primitives ]
214 [ describe-compounds ]
215 [ describe-predicates ]
220 : words. ( vocab -- )
224 : describe-metadata ( vocab -- )
226 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
227 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
230 [ "Meta-data" $heading $table ] unless-empty ;
232 : $vocab ( element -- )
235 [ describe-metadata ]
238 [ describe-children ]
241 : keyed-vocabs ( str quot -- seq )
244 [ [ 2dup ] dip swap call member? ] filter
246 ] assoc-map 2nip ; inline
248 : tagged ( tag -- assoc )
249 [ vocab-tags ] keyed-vocabs ;
251 : authored ( author -- assoc )
252 [ vocab-authors ] keyed-vocabs ;
254 : $tagged-vocabs ( element -- )
255 first tagged $vocab-roots ;
257 : $authored-vocabs ( element -- )
258 first authored $vocab-roots ;
260 : $all-tags ( element -- )
261 drop "Tags" $heading all-tags $tags ;
263 : $all-authors ( element -- )
264 drop "Authors" $heading all-authors $authors ;
266 INSTANCE: vocab topic
268 INSTANCE: vocab-link topic
270 M: vocab-spec article-title vocab-name " vocabulary" append ;
272 M: vocab-spec article-name vocab-name ;
274 M: vocab-spec article-content
275 vocab-name \ $vocab swap 2array ;
277 M: vocab-spec article-parent drop "vocab-index" ;
281 M: vocab-tag article-title
282 name>> "Vocabularies tagged ``" "''" surround ;
284 M: vocab-tag article-name name>> ;
286 M: vocab-tag article-content
287 \ $tagged-vocabs swap name>> 2array ;
289 M: vocab-tag article-parent drop "vocab-index" ;
291 M: vocab-tag summary article-title ;
293 M: vocab-author >link ;
295 M: vocab-author article-title
296 name>> "Vocabularies by " prepend ;
298 M: vocab-author article-name name>> ;
300 M: vocab-author article-content
301 \ $authored-vocabs swap name>> 2array ;
303 M: vocab-author article-parent drop "vocab-index" ;
305 M: vocab-author summary article-title ;