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
11 FROM: vocabs.hierarchy => child-vocabs ;
15 [ require ] [ lookup-vocab help ] bi ;
17 : vocab-row ( vocab -- row )
18 [ <$pretty-link> ] [ vocab-summary ] bi 2array ;
20 : vocab-headings ( -- headings )
22 { $strong "Vocabulary" }
26 : root-heading ( root -- )
27 [ "Children from " prepend ] [ "Children" ] if*
31 convert-prefixes [ vocab-row ] map vocab-headings prefix $table ;
33 : $vocab-roots ( assoc -- )
35 [ drop ] [ [ root-heading ] [ $vocabs ] bi* ] if-empty
38 TUPLE: vocab-tag name ;
40 INSTANCE: vocab-tag topic
42 C: <vocab-tag> vocab-tag
44 : $tags ( seq -- ) [ <vocab-tag> ] map $links ;
46 TUPLE: vocab-author name ;
48 INSTANCE: vocab-author topic
50 C: <vocab-author> vocab-author
52 : $authors ( seq -- ) [ <vocab-author> ] map $links ;
54 : describe-help ( vocab -- )
57 [ "Documentation" $heading ($link) ]
58 [ "Summary" $heading vocab-summary print-element ]
62 : describe-children ( vocab -- )
63 vocab-name child-vocabs
69 [ nl ] [ [ string>> ] keep write-object ] interleave
73 : describe-files ( vocab -- )
74 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 : vocab-is-not-loaded ( vocab -- )
223 "Not loaded" $heading
224 "You must first load this vocabulary to browse its documentation and words."
225 print-element vocab-name "USE: " prepend 1array $code ;
227 : describe-words ( vocab -- )
229 { [ dup lookup-vocab ] [ words $words ] }
230 { [ dup find-vocab-root ] [ vocab-is-not-loaded ] }
234 : words. ( vocab -- )
236 [ require ] [ words $words ] bi nl ;
238 : describe-metadata ( vocab -- )
240 [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
241 [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
244 [ "Meta-data" $heading $table ] unless-empty ;
246 : $vocab ( element -- )
249 [ describe-metadata ]
252 [ describe-children ]
255 : keyed-vocabs ( str quot -- seq )
256 [ all-vocabs-recursive ] 2dip
257 '[ [ _ swap @ member? ] filter no-prefixes ] assoc-map ; inline
259 : tagged ( tag -- assoc )
260 [ vocab-tags ] keyed-vocabs ;
262 : authored ( author -- assoc )
263 [ vocab-authors ] keyed-vocabs ;
265 : $tagged-vocabs ( element -- )
266 first tagged $vocab-roots ;
268 : $authored-vocabs ( element -- )
269 first authored $vocab-roots ;
271 : $all-tags ( element -- )
272 drop "Tags" $heading all-tags $tags ;
274 : $all-authors ( element -- )
275 drop "Authors" $heading all-authors $authors ;
277 INSTANCE: vocab topic
279 INSTANCE: vocab-link topic
281 M: vocab-spec valid-article? drop t ;
283 M: vocab-spec article-title vocab-name " vocabulary" append ;
285 M: vocab-spec article-name vocab-name ;
287 M: vocab-spec article-content
288 vocab-name \ $vocab swap 2array ;
290 M: vocab-spec article-parent drop "vocab-index" ;
294 M: vocab-tag valid-article? drop t ;
296 M: vocab-tag article-title
297 name>> "Vocabularies tagged “" "”" surround ;
299 M: vocab-tag article-name name>> ;
301 M: vocab-tag article-content
302 \ $tagged-vocabs swap name>> 2array ;
304 M: vocab-tag article-parent drop "vocab-tags" ;
306 M: vocab-tag summary article-title ;
308 M: vocab-author >link ;
310 M: vocab-author valid-article? drop t ;
312 M: vocab-author article-title
313 name>> "Vocabularies by " prepend ;
315 M: vocab-author article-name name>> ;
317 M: vocab-author article-content
318 \ $authored-vocabs swap name>> 2array ;
320 M: vocab-author article-parent drop "vocab-authors" ;
322 M: vocab-author summary article-title ;