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.intersection classes.mixin classes.predicate classes.singleton
5 classes.tuple classes.union combinators definitions effects generic
6 generic.single generic.standard generic.hook io io.pathnames
7 io.streams.string io.styles kernel make namespaces prettyprint
8 prettyprint.backend prettyprint.config prettyprint.custom
9 prettyprint.sections sequences sets slots sorting strings summary
10 words words.symbol words.constant words.alias vocabs ;
13 GENERIC: synopsis* ( defspec -- )
15 GENERIC: see* ( defspec -- )
17 : see ( defspec -- ) see* nl ;
19 : synopsis ( defspec -- str )
25 ] with-string-writer ;
27 : definer. ( defspec -- )
28 definer drop pprint-word ;
30 : comment. ( text -- )
31 H{ { font-style italic } } styled-text ;
33 GENERIC: print-stack-effect? ( word -- ? )
35 M: parsing-word print-stack-effect? drop f ;
36 M: symbol print-stack-effect? drop f ;
37 M: constant print-stack-effect? drop f ;
38 M: alias print-stack-effect? drop f ;
39 M: word print-stack-effect? drop t ;
41 : stack-effect. ( word -- )
42 [ print-stack-effect? ] [ stack-effect ] bi and
43 [ pprint-effect ] when* ;
47 : seeing-word ( word -- )
48 vocabulary>> dup [ lookup-vocab ] when pprinter-in set ;
50 : word-synopsis ( word -- )
58 M: word synopsis* word-synopsis ;
60 M: simple-generic synopsis* word-synopsis ;
62 M: standard-generic synopsis*
71 M: hook-generic synopsis*
76 [ "combination" word-prop var>> pprint* ]
82 [ "method-class" word-prop pprint-class ]
83 [ "method-generic" word-prop pprint-word ] tri ;
85 M: mixin-instance synopsis*
87 [ class>> pprint-word ]
88 [ mixin>> pprint-word ] tri ;
90 M: pathname synopsis* pprint* ;
94 0 margin set 1 line-limit set
100 [ stack-effect pprint-effect ]
103 ] with-string-writer ;
105 M: word summary synopsis ;
107 GENERIC: declarations. ( obj -- )
109 M: object declarations. drop ;
111 : declaration. ( word prop -- )
112 [ nip ] [ name>> word-prop ] 2bi
113 [ pprint-word ] [ drop ] if ;
115 M: word declarations.
123 } [ declaration. ] with each ;
125 : pprint-; ( -- ) \ ; pprint-word ;
132 <block dup definition pprint-elements block>
133 dup definer nip [ pprint-word ] when* declarations.
137 GENERIC: see-class* ( word -- )
139 M: union-class see-class*
140 <colon \ UNION: pprint-word
142 class-members pprint-elements pprint-; block> ;
144 M: intersection-class see-class*
145 <colon \ INTERSECTION: pprint-word
147 class-participants pprint-elements pprint-; block> ;
149 M: mixin-class see-class*
150 <block \ MIXIN: pprint-word
151 dup pprint-word <block
154 \ INSTANCE: pprint-word pprint-word pprint-word
155 ] with each block> block> ;
157 M: predicate-class see-class*
158 <colon \ PREDICATE: pprint-word
161 dup superclass-of pprint-word
163 "predicate-definition" word-prop pprint-elements
164 pprint-; block> block> ;
166 M: singleton-class see-class* ( class -- )
167 \ SINGLETON: pprint-word pprint-word ;
169 GENERIC: pprint-slot-name ( object -- )
171 M: string pprint-slot-name text ;
173 M: array pprint-slot-name
174 <flow \ { pprint-word
175 f <inset unclip text pprint-elements block>
176 \ } pprint-word block> ;
178 : unparse-slot ( slot-spec -- array )
181 dup class>> object eq? [
187 dup [ class>> object eq? not ] [ initial>> ] bi or [
194 : pprint-slot ( slot-spec -- )
196 dup length 1 = [ first ] when
199 : tuple-declarations. ( class -- )
200 \ final declaration. ;
202 : superclass. ( class -- )
203 superclass-of dup tuple eq? [ drop ] [ "<" text pprint-word ] if ;
205 M: tuple-class see-class*
206 <colon \ TUPLE: pprint-word
210 [ <block "slots" word-prop [ pprint-slot ] each block> pprint-; ]
211 [ tuple-declarations. ]
215 M: word see-class* drop ;
217 M: builtin-class see-class*
219 \ BUILTIN: pprint-word
221 [ <block "slots" word-prop [ pprint-slot ] each pprint-; block> ] bi
224 : see-class ( class -- )
227 [ seeing-word ] [ see-class* ] bi
233 [ [ class? ] [ symbol? not ] bi and [ nl nl ] when ]
235 dup [ class? ] [ symbol? ] bi and
236 [ drop ] [ call-next-method ] if
239 : seeing-implementors ( class -- seq )
241 [ [ reader? ] [ writer? ] bi or ] reject
242 [ lookup-method ] with map
245 : seeing-methods ( generic -- seq )
246 "methods" word-prop values natural-sort ;
251 natural-sort [ nl nl ] [ see* ] interleave ;
253 : methods ( word -- seq )
255 dup class? [ dup seeing-implementors % ] when
256 dup generic? [ dup seeing-methods % ] when
260 : see-methods ( word -- )