factor/library/syntax/see.factor

122 lines
2.9 KiB
Factor
Raw Normal View History

2005-02-06 00:21:26 -05:00
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2004-11-25 21:08:09 -05:00
IN: prettyprint
2005-08-21 14:25:05 -04:00
USING: generic hashtables io kernel lists namespaces sequences
styles words ;
2004-11-25 21:08:09 -05:00
2005-08-21 01:17:37 -04:00
: declaration. ( word prop -- )
tuck word-name word-prop [ bl pprint-word ] [ drop ] ifte ;
2004-11-25 21:08:09 -05:00
2005-08-21 01:17:37 -04:00
: declarations. ( word -- )
[
POSTPONE: parsing
POSTPONE: inline
POSTPONE: foldable
POSTPONE: flushable
2005-08-21 01:17:37 -04:00
] [ declaration. ] each-with ;
2004-11-25 21:08:09 -05:00
: comment. ( comment -- )
2005-08-21 01:17:37 -04:00
[ [[ font-style italic ]] ] text ;
2005-02-07 13:14:55 -05:00
: stack-picture% ( seq -- string )
[ word-name % " " % ] each ;
2005-08-21 01:17:37 -04:00
: effect>string ( effect -- string )
[
" " %
dup first stack-picture%
"-- " %
second stack-picture%
] make-string ;
2004-11-25 21:08:09 -05:00
2005-08-21 01:17:37 -04:00
: stack-effect ( word -- string )
dup "stack-effect" word-prop [ ] [
"infer-effect" word-prop
dup [ effect>string ] when
] ?ifte ;
2005-08-21 01:17:37 -04:00
: stack-effect. ( string -- )
[ bl "(" swap ")" append3 comment. ] when* ;
2005-03-23 22:49:40 -05:00
2005-08-21 01:17:37 -04:00
: in. ( word -- )
<block \ IN: pprint-word bl word-vocabulary f text block;
2005-08-21 01:17:37 -04:00
t newline ;
2005-08-21 01:17:37 -04:00
: definer. ( word -- )
dup definer pprint-word bl
dup pprint-word
2005-08-21 01:17:37 -04:00
stack-effect stack-effect.
f newline ;
2005-08-21 01:17:37 -04:00
GENERIC: (see) ( word -- )
2005-08-21 01:17:37 -04:00
M: word (see) definer. t newline ;
2005-08-21 01:17:37 -04:00
: documentation. ( word -- )
"documentation" word-prop [
"\n" split [ "#!" swap append comment. t newline ] each
] when* ;
: pprint-; \ ; pprint-word ;
2005-08-21 14:25:05 -04:00
2005-08-21 01:17:37 -04:00
: see-body ( quot word -- )
dup definer. <block dup documentation. swap pprint-elements
pprint-; declarations. block; ;
2005-08-21 01:17:37 -04:00
M: compound (see)
dup word-def swap see-body t newline ;
2005-08-21 01:17:37 -04:00
: method. ( word [[ class method ]] -- )
\ M: pprint-word bl
unswons pprint-word bl
swap pprint-word f newline
<block pprint-elements pprint-;
block; t newline ;
2005-08-21 01:17:37 -04:00
M: generic (see)
<block
2005-08-22 14:29:43 -04:00
dup dup "combination" word-prop
swap see-body block; t newline
2005-08-21 01:17:37 -04:00
dup methods [ method. ] each-with ;
2005-08-21 14:25:05 -04:00
GENERIC: class. ( word -- )
: methods. ( class -- )
#! List all methods implemented for this class.
dup metaclass [
dup implementors [
dup in. tuck "methods" word-prop hash* method.
] each-with
] [
drop
] ifte ;
M: union class.
\ UNION: pprint-word bl
dup pprint-word bl
"members" word-prop pprint-elements pprint-; t newline ;
2005-08-21 14:25:05 -04:00
M: complement class.
\ COMPLEMENT: pprint-word bl
dup pprint-word bl
"complement" word-prop pprint-word t newline ;
2005-08-21 14:25:05 -04:00
M: predicate class.
\ PREDICATE: pprint-word bl
dup "superclass" word-prop pprint-word bl
dup pprint-word f newline
2005-08-21 14:25:05 -04:00
<block
"definition" word-prop pprint-elements
pprint-; block; t newline ;
2005-08-21 14:25:05 -04:00
M: tuple-class class.
\ TUPLE: pprint-word bl
dup pprint-word bl
2005-08-21 14:25:05 -04:00
"slot-names" word-prop [ f text bl ] each
pprint-; t newline ;
2005-08-21 14:25:05 -04:00
M: word class. drop ;
: see ( word -- )
2005-08-21 14:25:05 -04:00
[ dup in. dup (see) dup class. methods. ] with-pprint ;