factor/library/syntax/see.factor

92 lines
1.9 KiB
Factor
Raw Normal View History

! Copyright (C) 2003, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2004-11-25 21:08:09 -05:00
IN: prettyprint
2006-05-15 01:01:47 -04:00
USING: arrays generic hashtables io kernel math namespaces
2005-10-25 21:52:26 -04:00
sequences strings styles words ;
2004-11-25 21:08:09 -05:00
2006-08-02 02:50:23 -04:00
GENERIC: definition ( spec -- quot ? )
M: word definition drop f f ;
M: compound definition word-def t ;
M: generic definition "combination" word-prop t ;
2006-08-02 03:10:09 -04:00
M: method-spec definition first2 method t ;
2006-08-02 02:50:23 -04:00
GENERIC: see ( spec -- )
GENERIC: declarations. ( obj -- )
M: object declarations. drop ;
2005-08-21 01:17:37 -04:00
: declaration. ( word prop -- )
2005-09-24 15:21:17 -04:00
tuck word-name word-prop [ pprint-word ] [ drop ] if ;
2004-11-25 21:08:09 -05:00
2006-08-02 02:50:23 -04:00
M: word declarations.
2005-11-29 23:49:59 -05:00
{
POSTPONE: parsing
POSTPONE: inline
POSTPONE: foldable
2005-11-29 23:49:59 -05:00
} [ declaration. ] each-with ;
2004-11-25 21:08:09 -05:00
2006-08-02 02:50:23 -04:00
: pprint-; \ ; pprint-word ;
2005-12-28 20:25:17 -05:00
2006-08-02 02:50:23 -04:00
: (see) ( spec -- )
[
dup (synopsis)
dup definition [
H{ } <block
pprint-elements pprint-; declarations.
block;
] [
2drop
] if newline
] with-pprint ;
2005-12-28 20:25:17 -05:00
2006-08-02 02:50:23 -04:00
M: method-spec see (see) ;
2005-02-07 13:14:55 -05:00
2006-08-02 02:50:23 -04:00
GENERIC: see-methods* ( word -- seq )
2006-08-02 02:50:23 -04:00
M: generic see-methods*
dup order [ swap 2array ] map-with ;
2005-10-03 19:53:32 -04:00
2006-08-02 02:50:23 -04:00
M: class see-methods*
dup implementors [ 2array ] map-with ;
2006-08-02 03:10:09 -04:00
M: word see-methods* drop f ;
2006-08-02 02:50:23 -04:00
: see-methods ( word -- )
see-methods* [ see ] each ;
2006-08-02 02:50:23 -04:00
GENERIC: see-class* ( word -- )
2005-08-21 14:25:05 -04:00
2006-08-02 02:50:23 -04:00
M: union see-class*
2005-08-29 01:00:55 -04:00
\ UNION: pprint-word
dup pprint-word
2005-10-05 02:01:06 -04:00
members pprint-elements pprint-; ;
2005-08-21 14:25:05 -04:00
2006-08-02 02:50:23 -04:00
M: predicate see-class*
2005-08-29 01:00:55 -04:00
\ PREDICATE: pprint-word
dup superclass pprint-word
2005-08-29 01:00:55 -04:00
dup pprint-word
H{ } <block
2005-08-21 14:25:05 -04:00
"definition" word-prop pprint-elements
2005-10-05 02:01:06 -04:00
pprint-; block; ;
2005-08-21 14:25:05 -04:00
2006-08-02 02:50:23 -04:00
M: tuple-class see-class*
2005-08-29 01:00:55 -04:00
\ TUPLE: pprint-word
dup pprint-word
"slot-names" word-prop [ text ] each
2005-10-05 02:01:06 -04:00
pprint-; ;
2005-08-21 14:25:05 -04:00
2006-08-02 02:50:23 -04:00
M: word see-class* drop ;
2005-08-21 14:25:05 -04:00
2006-08-02 02:50:23 -04:00
: see-class ( word -- )
2005-10-03 19:53:32 -04:00
[
2006-08-02 02:50:23 -04:00
dup class?
[ see-class* newline ] [ drop ] if
2005-10-03 19:53:32 -04:00
] with-pprint ;
2006-08-02 02:50:23 -04:00
M: word see dup (see) dup see-class see-methods ;