1 ! Copyright (C) 2007, 2009 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 definitions.icons ;
12 : $pretty-link ( element -- )
13 [ first definition-icon 1array $image " " print-element ]
17 : <$pretty-link> ( definition -- element )
18 1array \ $pretty-link prefix ;
20 : vocab-row ( vocab -- row )
21 [ <$pretty-link> ] [ vocab-summary ] bi 2array ;
23 : vocab-headings ( -- headings )
25 { $strong "Vocabulary" }
29 : root-heading ( root -- )
30 [ "Children from " prepend ] [ "Children" ] if*
34 [ 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 all-child-vocabs $vocab-roots ;
71 [ nl ] [ [ string>> ] keep write-object ] interleave
75 : describe-files ( vocab -- )
76 vocab-files [ <pathname> ] map [
83 : describe-tuple-classes ( classes -- )
85 "Tuple classes" $subheading
88 [ superclass <$pretty-link> ]
89 [ "slots" word-prop [ name>> ] map " " join <$snippet> ]
92 { { $strong "Class" } { $strong "Superclass" } { $strong "Slots" } } prefix
96 : describe-predicate-classes ( classes -- )
98 "Predicate classes" $subheading
101 [ superclass <$pretty-link> ]
104 { { $strong "Class" } { $strong "Superclass" } } prefix
108 : (describe-classes) ( classes heading -- )
111 [ <$pretty-link> 1array ] map $table
114 : describe-builtin-classes ( classes -- )
115 "Builtin classes" (describe-classes) ;
117 : describe-singleton-classes ( classes -- )
118 "Singleton classes" (describe-classes) ;
120 : describe-mixin-classes ( classes -- )
121 "Mixin classes" (describe-classes) ;
123 : describe-union-classes ( classes -- )
124 "Union classes" (describe-classes) ;
126 : describe-intersection-classes ( classes -- )
127 "Intersection classes" (describe-classes) ;
129 : describe-classes ( classes -- )
130 [ builtin-class? ] partition
131 [ tuple-class? ] partition
132 [ singleton-class? ] partition
133 [ predicate-class? ] partition
134 [ mixin-class? ] partition
135 [ union-class? ] partition
136 [ intersection-class? ] filter
138 [ describe-builtin-classes ]
139 [ describe-tuple-classes ]
140 [ describe-singleton-classes ]
141 [ describe-predicate-classes ]
142 [ describe-mixin-classes ]
143 [ describe-union-classes ]
144 [ describe-intersection-classes ]
147 : word-syntax ( word -- string/f )
148 \ $syntax swap word-help elements dup length 1 =
149 [ first second ] [ drop f ] if ;
151 : describe-parsing ( words -- )
153 "Parsing words" $subheading
156 [ word-syntax dup [ <$snippet> ] when ]
159 { { $strong "Word" } { $strong "Syntax" } } prefix
163 : word-row ( word -- element )
165 [ stack-effect dup [ effect>string <$snippet> ] when ]
168 : word-headings ( -- element )
169 { { $strong "Word" } { $strong "Stack effect" } } ;
171 : words-table ( words -- )
172 [ word-row ] map word-headings prefix $table ;
174 : (describe-words) ( words heading -- )
175 '[ _ $subheading words-table ] unless-empty ;
177 : describe-generics ( words -- )
178 "Generic words" (describe-words) ;
180 : describe-macros ( words -- )
181 "Macro words" (describe-words) ;
183 : describe-primitives ( words -- )
184 "Primitives" (describe-words) ;
186 : describe-compounds ( words -- )
187 "Ordinary words" (describe-words) ;
189 : describe-predicates ( words -- )
190 "Class predicate words" (describe-words) ;
192 : describe-symbols ( words -- )
194 "Symbol words" $subheading
195 [ <$pretty-link> 1array ] map $table
198 : $words ( words -- )
203 [ [ class? ] filter describe-classes ]
205 [ [ class? ] [ symbol? ] bi and not ] filter
206 [ parsing-word? ] partition
207 [ generic? ] partition
209 [ symbol? ] partition
210 [ primitive? ] partition
211 [ predicate? ] partition swap
214 [ describe-generics ]
217 [ describe-primitives ]
218 [ describe-compounds ]
219 [ describe-predicates ]
224 : words. ( vocab -- )
226 [ require ] [ words $words ] bi nl ;
228 : describe-metadata ( vocab -- )
230 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
231 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
234 [ "Meta-data" $heading $table ] unless-empty ;
236 : $vocab ( element -- )
239 [ describe-metadata ]
242 [ describe-children ]
245 : keyed-vocabs ( str quot -- seq )
246 [ all-vocabs ] 2dip '[ [ _ swap @ member? ] filter ] assoc-map ; 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-tags" ;
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-authors" ;
305 M: vocab-author summary article-title ;