1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.builtin
4 classes.error classes.intersection classes.mixin
5 classes.predicate classes.singleton classes.tuple classes.union
6 combinators definitions effects generic generic.hook
7 generic.single generic.standard io io.pathnames
8 io.streams.string io.styles kernel make namespaces prettyprint
9 prettyprint.backend prettyprint.config prettyprint.custom
10 prettyprint.sections sequences sets slots sorting strings
11 summary vocabs words words.alias words.constant words.symbol ;
14 GENERIC: synopsis* ( defspec -- )
16 GENERIC: see* ( defspec -- )
18 : see ( defspec -- ) see* nl ;
20 : synopsis ( defspec -- str )
26 [ [ synopsis* ] with-in ] with-string-writer
29 : definer. ( defspec -- )
30 definer drop pprint-word ;
32 : comment. ( text -- )
33 H{ { font-style italic } } styled-text ;
35 GENERIC: print-stack-effect? ( word -- ? )
37 M: parsing-word print-stack-effect? drop f ;
38 M: symbol print-stack-effect? drop f ;
39 M: constant print-stack-effect? drop f ;
40 M: alias print-stack-effect? drop f ;
41 M: word print-stack-effect? drop t ;
43 : stack-effect. ( word -- )
44 [ print-stack-effect? ] [ stack-effect ] bi and
45 [ pprint-effect ] when* ;
49 : seeing-word ( word -- )
50 vocabulary>> dup [ lookup-vocab ] when pprinter-in namespaces:set ;
52 : word-synopsis ( word -- )
60 M: word synopsis* word-synopsis ;
62 M: simple-generic synopsis* word-synopsis ;
64 M: standard-generic synopsis*
73 M: hook-generic synopsis*
78 [ "combination" word-prop var>> pprint* ]
84 [ "method-class" word-prop pprint-class ]
85 [ "method-generic" word-prop pprint-word ] tri ;
87 M: mixin-instance synopsis*
89 [ class>> pprint-word ]
90 [ mixin>> pprint-word ] tri ;
92 M: pathname synopsis* pprint* ;
96 0 margin namespaces:set
97 1 line-limit namespaces:set
103 [ stack-effect pprint-effect ]
106 ] with-string-writer ;
108 M: word summary synopsis ;
110 GENERIC: declarations. ( obj -- )
112 M: object declarations. drop ;
114 : declaration. ( word prop -- )
115 [ nip ] [ name>> word-prop ] 2bi
116 [ pprint-word ] [ drop ] if ;
118 M: word declarations.
126 } [ declaration. ] with each ;
128 : pprint-; ( -- ) \ ; pprint-word ;
132 12 nesting-limit namespaces:set
133 100 length-limit namespaces:set
135 <block dup definition pprint-elements block>
136 dup definer nip [ pprint-word ] when* declarations.
140 GENERIC: see-class* ( word -- )
142 M: union-class see-class*
143 <colon \ UNION: pprint-word
145 class-members pprint-elements pprint-; block> ;
147 M: intersection-class see-class*
148 <colon \ INTERSECTION: pprint-word
150 class-participants pprint-elements pprint-; block> ;
152 M: mixin-class see-class*
153 <block \ MIXIN: pprint-word
154 dup pprint-word <block
157 \ INSTANCE: pprint-word pprint-word pprint-word
158 ] with each block> block> ;
160 M: predicate-class see-class*
161 <colon \ PREDICATE: pprint-word
164 dup superclass-of pprint-word
166 "predicate-definition" word-prop pprint-elements
167 pprint-; block> block> ;
169 M: singleton-class see-class*
170 \ SINGLETON: pprint-word pprint-word ;
172 GENERIC: pprint-slot-name ( object -- )
174 M: string pprint-slot-name text ;
176 M: array pprint-slot-name
177 <flow \ { pprint-word
178 f <inset unclip text pprint-elements block>
179 \ } pprint-word block> ;
181 : unparse-slot ( slot-spec -- array )
184 dup class>> object eq? [
190 dup [ class>> object eq? not ] [ initial>> ] bi or [
197 : pprint-slot ( slot-spec -- )
199 dup length 1 = [ first ] when
202 : tuple-declarations. ( class -- )
203 \ final declaration. ;
205 : superclass. ( class -- )
206 superclass-of dup tuple eq? [ drop ] [ "<" text pprint-word ] if ;
208 M: tuple-class see-class*
209 <colon \ TUPLE: pprint-word
213 [ <block "slots" word-prop [ pprint-slot ] each block> pprint-; ]
214 [ tuple-declarations. ]
218 M: word see-class* drop ;
220 M: builtin-class see-class*
222 \ BUILTIN: pprint-word
224 [ <block "slots" word-prop [ pprint-slot ] each pprint-; block> ] bi
227 : see-class ( class -- )
230 [ seeing-word ] [ see-class* ] bi
236 [ [ class? ] [ symbol? not ] bi and [ nl nl ] when ]
238 dup [ class? ] [ symbol? ] bi and
239 [ drop ] [ call-next-method ] if
242 M: error-class see-class*
243 <colon \ ERROR: pprint-word
247 [ <block "slots" word-prop [ name>> pprint-slot-name ] each block> pprint-; ]
248 [ tuple-declarations. ]
252 M: error-class see* see-class ;
254 : seeing-implementors ( class -- seq )
256 [ [ reader? ] [ writer? ] bi or ] reject
257 [ lookup-method ] with map
260 : seeing-methods ( generic -- seq )
261 "methods" word-prop values natural-sort ;
266 natural-sort [ nl nl ] [ see* ] interleave ;
268 : methods ( word -- seq )
270 dup class? [ dup seeing-implementors % ] when
271 dup generic? [ dup seeing-methods % ] when
275 : see-methods ( word -- )