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 ;
72 [ nl ] [ [ string>> ] keep write-object ] interleave
76 : describe-files ( vocab -- )
77 vocab-files [ <pathname> ] map [
84 : describe-tuple-classes ( classes -- )
86 "Tuple classes" $subheading
89 [ superclass <$pretty-link> ]
90 [ "slots" word-prop [ name>> ] map " " join <$snippet> ]
93 { { $strong "Class" } { $strong "Superclass" } { $strong "Slots" } } prefix
97 : describe-predicate-classes ( classes -- )
99 "Predicate classes" $subheading
102 [ superclass <$pretty-link> ]
105 { { $strong "Class" } { $strong "Superclass" } } prefix
109 : (describe-classes) ( classes heading -- )
112 [ <$pretty-link> 1array ] map $table
115 : describe-builtin-classes ( classes -- )
116 "Builtin classes" (describe-classes) ;
118 : describe-singleton-classes ( classes -- )
119 "Singleton classes" (describe-classes) ;
121 : describe-mixin-classes ( classes -- )
122 "Mixin classes" (describe-classes) ;
124 : describe-union-classes ( classes -- )
125 "Union classes" (describe-classes) ;
127 : describe-intersection-classes ( classes -- )
128 "Intersection classes" (describe-classes) ;
130 : describe-classes ( classes -- )
131 [ builtin-class? ] partition
132 [ tuple-class? ] partition
133 [ singleton-class? ] partition
134 [ predicate-class? ] partition
135 [ mixin-class? ] partition
136 [ union-class? ] partition
137 [ intersection-class? ] filter
139 [ describe-builtin-classes ]
140 [ describe-tuple-classes ]
141 [ describe-singleton-classes ]
142 [ describe-predicate-classes ]
143 [ describe-mixin-classes ]
144 [ describe-union-classes ]
145 [ describe-intersection-classes ]
148 : word-syntax ( word -- string/f )
149 \ $syntax swap word-help elements dup length 1 =
150 [ first second ] [ drop f ] if ;
152 : describe-parsing ( words -- )
154 "Parsing words" $subheading
157 [ word-syntax dup [ <$snippet> ] when ]
160 { { $strong "Word" } { $strong "Syntax" } } prefix
164 : word-row ( word -- element )
166 [ stack-effect dup [ effect>string <$snippet> ] when ]
169 : word-headings ( -- element )
170 { { $strong "Word" } { $strong "Stack effect" } } ;
172 : words-table ( words -- )
173 [ word-row ] map word-headings prefix $table ;
175 : (describe-words) ( words heading -- )
176 '[ _ $subheading words-table ] unless-empty ;
178 : describe-generics ( words -- )
179 "Generic words" (describe-words) ;
181 : describe-macros ( words -- )
182 "Macro words" (describe-words) ;
184 : describe-primitives ( words -- )
185 "Primitives" (describe-words) ;
187 : describe-compounds ( words -- )
188 "Ordinary words" (describe-words) ;
190 : describe-predicates ( words -- )
191 "Class predicate words" (describe-words) ;
193 : describe-symbols ( words -- )
195 "Symbol words" $subheading
196 [ <$pretty-link> 1array ] map $table
199 : $words ( words -- )
204 [ [ class? ] filter describe-classes ]
206 [ [ class? ] [ symbol? ] bi and not ] filter
207 [ parsing-word? ] partition
208 [ generic? ] partition
210 [ symbol? ] partition
211 [ primitive? ] partition
212 [ predicate? ] partition swap
215 [ describe-generics ]
218 [ describe-primitives ]
219 [ describe-compounds ]
220 [ describe-predicates ]
225 : words. ( vocab -- )
227 [ require ] [ words $words ] bi ;
229 : describe-metadata ( vocab -- )
231 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
232 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
235 [ "Meta-data" $heading $table ] unless-empty ;
237 : $vocab ( element -- )
240 [ describe-metadata ]
243 [ describe-children ]
246 : keyed-vocabs ( str quot -- seq )
249 [ [ 2dup ] dip swap call member? ] filter
251 ] assoc-map 2nip ; inline
253 : tagged ( tag -- assoc )
254 [ vocab-tags ] keyed-vocabs ;
256 : authored ( author -- assoc )
257 [ vocab-authors ] keyed-vocabs ;
259 : $tagged-vocabs ( element -- )
260 first tagged $vocab-roots ;
262 : $authored-vocabs ( element -- )
263 first authored $vocab-roots ;
265 : $all-tags ( element -- )
266 drop "Tags" $heading all-tags $tags ;
268 : $all-authors ( element -- )
269 drop "Authors" $heading all-authors $authors ;
271 INSTANCE: vocab topic
273 INSTANCE: vocab-link topic
275 M: vocab-spec article-title vocab-name " vocabulary" append ;
277 M: vocab-spec article-name vocab-name ;
279 M: vocab-spec article-content
280 vocab-name \ $vocab swap 2array ;
282 M: vocab-spec article-parent drop "vocab-index" ;
286 M: vocab-tag article-title
287 name>> "Vocabularies tagged “" "”" surround ;
289 M: vocab-tag article-name name>> ;
291 M: vocab-tag article-content
292 \ $tagged-vocabs swap name>> 2array ;
294 M: vocab-tag article-parent drop "vocab-tags" ;
296 M: vocab-tag summary article-title ;
298 M: vocab-author >link ;
300 M: vocab-author article-title
301 name>> "Vocabularies by " prepend ;
303 M: vocab-author article-name name>> ;
305 M: vocab-author article-content
306 \ $authored-vocabs swap name>> 2array ;
308 M: vocab-author article-parent drop "vocab-authors" ;
310 M: vocab-author summary article-title ;