]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/vocabs/browser/browser.factor
Fix conflict in images vocab
[factor.git] / basis / tools / vocabs / browser / browser.factor
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
12
13 : <$pretty-link> ( definition -- element )
14     [
15         [ definition-icon 1array \ $image prefix ]
16         [ drop " " ]
17         [ 1array \ $definition-link prefix ]
18         tri
19     ] output>array ;
20
21 : vocab-row ( vocab -- row )
22     [ <$pretty-link> ] [ vocab-summary ] bi 2array ;
23
24 : vocab-headings ( -- headings )
25     {
26         { $strong "Vocabulary" }
27         { $strong "Summary" }
28     } ;
29
30 : root-heading ( root -- )
31     [ "Children from " prepend ] [ "Children" ] if*
32     $heading ;
33
34 : $vocabs ( seq -- )
35     [ vocab-row ] map vocab-headings prefix $table ;
36
37 : $vocab-roots ( assoc -- )
38     [
39         [ drop ] [ [ root-heading ] [ $vocabs ] bi* ] if-empty
40     ] assoc-each ;
41
42 TUPLE: vocab-tag name ;
43
44 INSTANCE: vocab-tag topic
45
46 C: <vocab-tag> vocab-tag
47
48 : $tags ( seq -- ) [ <vocab-tag> ] map $links ;
49
50 TUPLE: vocab-author name ;
51
52 INSTANCE: vocab-author topic
53
54 C: <vocab-author> vocab-author
55
56 : $authors ( seq -- ) [ <vocab-author> ] map $links ;
57
58 : describe-help ( vocab -- )
59     [
60         dup vocab-help
61         [ "Documentation" $heading ($link) ]
62         [ "Summary" $heading vocab-summary print-element ]
63         ?if
64     ] unless-empty ;
65
66 : describe-children ( vocab -- )
67     vocab-name all-child-vocabs $vocab-roots ;
68
69 : describe-files ( vocab -- )
70     vocab-files [ <pathname> ] map [
71         "Files" $heading
72         [
73             snippet-style get [
74                 code-style get [
75                     stack.
76                 ] with-nesting
77             ] with-style
78         ] ($block)
79     ] unless-empty ;
80
81 : describe-tuple-classes ( classes -- )
82     [
83         "Tuple classes" $subheading
84         [
85             [ <$pretty-link> ]
86             [ superclass <$pretty-link> ]
87             [ "slots" word-prop [ name>> ] map " " join <$snippet> ]
88             tri 3array
89         ] map
90         { { $strong "Class" } { $strong "Superclass" } { $strong "Slots" } } prefix
91         $table
92     ] unless-empty ;
93
94 : describe-predicate-classes ( classes -- )
95     [
96         "Predicate classes" $subheading
97         [
98             [ <$pretty-link> ]
99             [ superclass <$pretty-link> ]
100             bi 2array
101         ] map
102         { { $strong "Class" } { $strong "Superclass" } } prefix
103         $table
104     ] unless-empty ;
105
106 : (describe-classes) ( classes heading -- )
107     '[
108         _ $subheading
109         [ <$pretty-link> 1array ] map $table
110     ] unless-empty ;
111
112 : describe-builtin-classes ( classes -- )
113     "Builtin classes" (describe-classes) ;
114
115 : describe-singleton-classes ( classes -- )
116     "Singleton classes" (describe-classes) ;
117
118 : describe-mixin-classes ( classes -- )
119     "Mixin classes" (describe-classes) ;
120
121 : describe-union-classes ( classes -- )
122     "Union classes" (describe-classes) ;
123
124 : describe-intersection-classes ( classes -- )
125     "Intersection classes" (describe-classes) ;
126
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
135     {
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 ]
143     } spread ;
144
145 : word-syntax ( word -- string/f )
146     \ $syntax swap word-help elements dup length 1 =
147     [ first second ] [ drop f ] if ;
148
149 : describe-parsing ( words -- )
150     [
151         "Parsing words" $subheading
152         [
153             [ <$pretty-link> ]
154             [ word-syntax dup [ <$snippet> ] when ]
155             bi 2array
156         ] map
157         { { $strong "Word" } { $strong "Syntax" } } prefix
158         $table
159     ] unless-empty ;
160
161 : word-row ( word -- element )
162     [ <$pretty-link> ]
163     [ stack-effect dup [ effect>string <$snippet> ] when ]
164     bi 2array ;
165
166 : word-headings ( -- element )
167     { { $strong "Word" } { $strong "Stack effect" } } ;
168
169 : words-table ( words -- )
170     [ word-row ] map word-headings prefix $table ;
171
172 : (describe-words) ( words heading -- )
173     '[ _ $subheading words-table ] unless-empty ;
174
175 : describe-generics ( words -- )
176     "Generic words" (describe-words) ;
177
178 : describe-macros ( words -- )
179     "Macro words" (describe-words) ;
180
181 : describe-primitives ( words -- )
182     "Primitives" (describe-words) ;
183
184 : describe-compounds ( words -- )
185     "Ordinary words" (describe-words) ;
186
187 : describe-predicates ( words -- )
188     "Class predicate words" (describe-words) ;
189
190 : describe-symbols ( words -- )
191     [
192         "Symbol words" $subheading
193         [ <$pretty-link> 1array ] map $table
194     ] unless-empty ;
195
196 : $words ( words -- )
197     [
198         "Words" $heading
199
200         natural-sort
201         [ [ class? ] filter describe-classes ]
202         [
203             [ [ class? ] [ symbol? ] bi and not ] filter
204             [ parsing-word? ] partition
205             [ generic? ] partition
206             [ macro? ] partition
207             [ symbol? ] partition
208             [ primitive? ] partition
209             [ predicate? ] partition swap
210             {
211                 [ describe-parsing ]
212                 [ describe-generics ]
213                 [ describe-macros ]
214                 [ describe-symbols ]
215                 [ describe-primitives ]
216                 [ describe-compounds ]
217                 [ describe-predicates ]
218             } spread
219         ] bi
220     ] unless-empty ;
221
222 : words. ( vocab -- )
223     last-element off
224     [ require ] [ words $words ] bi ;
225
226 : describe-metadata ( vocab -- )
227     [
228         [ vocab-tags [ "Tags:" swap \ $tags prefix 2array , ] unless-empty ]
229         [ vocab-authors [ "Authors:" swap \ $authors prefix 2array , ] unless-empty ]
230         bi
231     ] { } make
232     [ "Meta-data" $heading $table ] unless-empty ;
233
234 : $vocab ( element -- )
235     first {
236         [ describe-help ]
237         [ describe-metadata ]
238         [ words $words ]
239         [ describe-files ]
240         [ describe-children ]
241     } cleave ;
242
243 : keyed-vocabs ( str quot -- seq )
244     all-vocabs [
245         swap [
246             [ [ 2dup ] dip swap call member? ] filter
247         ] dip swap
248     ] assoc-map 2nip ; inline
249
250 : tagged ( tag -- assoc )
251     [ vocab-tags ] keyed-vocabs ;
252
253 : authored ( author -- assoc )
254     [ vocab-authors ] keyed-vocabs ;
255
256 : $tagged-vocabs ( element -- )
257     first tagged $vocab-roots ;
258
259 : $authored-vocabs ( element -- )
260     first authored $vocab-roots ;
261
262 : $all-tags ( element -- )
263     drop "Tags" $heading all-tags $tags ;
264
265 : $all-authors ( element -- )
266     drop "Authors" $heading all-authors $authors ;
267
268 INSTANCE: vocab topic
269
270 INSTANCE: vocab-link topic
271
272 M: vocab-spec article-title vocab-name " vocabulary" append ;
273
274 M: vocab-spec article-name vocab-name ;
275
276 M: vocab-spec article-content
277     vocab-name \ $vocab swap 2array ;
278
279 M: vocab-spec article-parent drop "vocab-index" ;
280
281 M: vocab-tag >link ;
282
283 M: vocab-tag article-title
284     name>> "Vocabularies tagged “" "”" surround ;
285
286 M: vocab-tag article-name name>> ;
287
288 M: vocab-tag article-content
289     \ $tagged-vocabs swap name>> 2array ;
290
291 M: vocab-tag article-parent drop "vocab-index" ;
292
293 M: vocab-tag summary article-title ;
294
295 M: vocab-author >link ;
296
297 M: vocab-author article-title
298     name>> "Vocabularies by " prepend ;
299
300 M: vocab-author article-name name>> ;
301
302 M: vocab-author article-content
303     \ $authored-vocabs swap name>> 2array ;
304
305 M: vocab-author article-parent drop "vocab-index" ;
306
307 M: vocab-author summary article-title ;