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 combinators.smart definitions.icons ;
11 IN: tools.vocabs.browser
13 : <$pretty-link> ( definition -- element )
15 [ definition-icon 1array \ $image prefix ]
17 [ 1array \ $definition-link prefix ]
21 : vocab-row ( vocab -- row )
22 [ <$pretty-link> ] [ vocab-summary ] bi 2array ;
24 : vocab-headings ( -- headings )
26 { $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 <$pretty-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 <$pretty-link> ]
102 { { $strong "Class" } { $strong "Superclass" } } prefix
106 : (describe-classes) ( classes heading -- )
109 [ <$pretty-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 : word-row ( word -- element )
163 [ stack-effect dup [ effect>string <$snippet> ] when ]
166 : word-headings ( -- element )
167 { { $strong "Word" } { $strong "Stack effect" } } ;
169 : words-table ( words -- )
170 [ word-row ] map word-headings prefix $table ;
172 : (describe-words) ( words heading -- )
173 '[ _ $subheading words-table ] unless-empty ;
175 : describe-generics ( words -- )
176 "Generic words" (describe-words) ;
178 : describe-macros ( words -- )
179 "Macro words" (describe-words) ;
181 : describe-primitives ( words -- )
182 "Primitives" (describe-words) ;
184 : describe-compounds ( words -- )
185 "Ordinary words" (describe-words) ;
187 : describe-predicates ( words -- )
188 "Class predicate words" (describe-words) ;
190 : describe-symbols ( words -- )
192 "Symbol words" $subheading
193 [ <$pretty-link> 1array ] map $table
196 : $words ( words -- )
201 [ [ class? ] filter describe-classes ]
203 [ [ class? ] [ symbol? ] bi and not ] filter
204 [ parsing-word? ] partition
205 [ generic? ] partition
207 [ symbol? ] partition
208 [ primitive? ] partition
209 [ predicate? ] partition swap
212 [ describe-generics ]
215 [ describe-primitives ]
216 [ describe-compounds ]
217 [ describe-predicates ]
222 : words. ( vocab -- )
224 [ require ] [ words $words ] bi ;
226 : describe-metadata ( vocab -- )
228 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
229 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
232 [ "Meta-data" $heading $table ] unless-empty ;
234 : $vocab ( element -- )
237 [ describe-metadata ]
240 [ describe-children ]
243 : keyed-vocabs ( str quot -- seq )
246 [ [ 2dup ] dip swap call member? ] filter
248 ] assoc-map 2nip ; inline
250 : tagged ( tag -- assoc )
251 [ vocab-tags ] keyed-vocabs ;
253 : authored ( author -- assoc )
254 [ vocab-authors ] keyed-vocabs ;
256 : $tagged-vocabs ( element -- )
257 first tagged $vocab-roots ;
259 : $authored-vocabs ( element -- )
260 first authored $vocab-roots ;
262 : $all-tags ( element -- )
263 drop "Tags" $heading all-tags $tags ;
265 : $all-authors ( element -- )
266 drop "Authors" $heading all-authors $authors ;
268 INSTANCE: vocab topic
270 INSTANCE: vocab-link topic
272 M: vocab-spec article-title vocab-name " vocabulary" append ;
274 M: vocab-spec article-name vocab-name ;
276 M: vocab-spec article-content
277 vocab-name \ $vocab swap 2array ;
279 M: vocab-spec article-parent drop "vocab-index" ;
283 M: vocab-tag article-title
284 name>> "Vocabularies tagged “" "”" surround ;
286 M: vocab-tag article-name name>> ;
288 M: vocab-tag article-content
289 \ $tagged-vocabs swap name>> 2array ;
291 M: vocab-tag article-parent drop "vocab-index" ;
293 M: vocab-tag summary article-title ;
295 M: vocab-author >link ;
297 M: vocab-author article-title
298 name>> "Vocabularies by " prepend ;
300 M: vocab-author article-name name>> ;
302 M: vocab-author article-content
303 \ $authored-vocabs swap name>> 2array ;
305 M: vocab-author article-parent drop "vocab-index" ;
307 M: vocab-author summary article-title ;