factor/library/syntax/see.factor

126 lines
2.8 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-12-24 18:29:31 -05:00
USING: arrays generic hashtables io kernel lists math namespaces
2005-10-25 21:52:26 -04:00
sequences strings styles words ;
2004-11-25 21:08:09 -05:00
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
2005-08-21 01:17:37 -04:00
: declarations. ( word -- )
2005-11-29 23:49:59 -05:00
{
POSTPONE: parsing
POSTPONE: inline
POSTPONE: foldable
POSTPONE: flushable
2005-11-29 23:49:59 -05:00
} [ declaration. ] each-with ;
2004-11-25 21:08:09 -05:00
2005-12-28 20:25:17 -05:00
: in. ( word -- )
<block \ IN: pprint-word word-vocabulary plain-text block; ;
: (synopsis) ( word -- )
dup in. dup definer pprint-word pprint-word ;
: comment. ( comment -- )
2005-12-28 20:25:17 -05:00
[ H{ { font-style italic } } text ] when* ;
2005-02-07 13:14:55 -05:00
2006-01-05 00:33:12 -05:00
: stack-picture ( seq -- string )
2005-12-24 18:29:31 -05:00
dup integer? [ object <array> ] when
2006-01-05 00:33:12 -05:00
[ word-name ] map " " join ;
2005-08-21 01:17:37 -04:00
: effect>string ( effect -- string )
[
2006-01-05 00:33:12 -05:00
"(" %
dup first stack-picture %
" -- " %
second stack-picture %
2005-12-28 20:25:17 -05:00
")" %
2005-08-25 15:27:38 -04:00
] "" make ;
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
2005-09-24 15:21:17 -04:00
] ?if ;
2005-10-10 21:12:53 -04:00
: synopsis ( word -- string )
2005-12-28 20:25:17 -05:00
[
0 margin set [
dup (synopsis) stack-effect comment.
] with-pprint
] string-out ;
2005-10-03 19:53:32 -04:00
2005-08-21 01:17:37 -04:00
GENERIC: (see) ( word -- )
2005-10-03 19:53:32 -04:00
M: word (see) drop ;
: pprint-; \ ; pprint-word ;
2005-08-21 14:25:05 -04:00
2005-08-21 01:17:37 -04:00
: see-body ( quot word -- )
2005-12-28 20:25:17 -05:00
<block swap pprint-elements pprint-; declarations. block; ;
2005-08-21 01:17:37 -04:00
M: compound (see)
2005-10-03 19:53:32 -04:00
dup word-def swap see-body ;
2005-11-27 17:45:48 -05:00
: method. ( word class method -- )
2005-08-29 01:00:55 -04:00
\ M: pprint-word
2005-11-27 17:45:48 -05:00
>r pprint-word pprint-word r>
<block pprint-elements pprint-; block; ;
2005-08-21 01:17:37 -04:00
M: generic (see)
2005-10-03 19:53:32 -04:00
dup dup "combination" word-prop swap see-body
2005-11-27 17:45:48 -05:00
dup methods [ newline first2 method. ] each-with ;
2005-08-21 14:25:05 -04:00
GENERIC: class. ( word -- )
: methods. ( class -- )
#! List all methods implemented for this class.
dup class? [
2005-08-21 14:25:05 -04:00
dup implementors [
2005-10-05 02:01:06 -04:00
newline
2005-11-27 17:45:48 -05:00
dup in. tuck dupd "methods" word-prop hash method.
2005-08-21 14:25:05 -04:00
] each-with
] [
drop
2005-09-24 15:21:17 -04:00
] if ;
2005-08-21 14:25:05 -04:00
M: union class.
2005-10-05 02:01:06 -04:00
newline
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
M: predicate class.
2005-10-05 02:01:06 -04:00
newline
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
2005-08-21 14:25:05 -04:00
<block
"definition" word-prop pprint-elements
2005-10-05 02:01:06 -04:00
pprint-; block; ;
2005-08-21 14:25:05 -04:00
M: tuple-class class.
2005-10-05 02:01:06 -04:00
newline
2005-08-29 01:00:55 -04:00
\ TUPLE: pprint-word
dup pprint-word
2005-11-29 23:49:59 -05:00
"slot-names" word-prop [ plain-text ] each
2005-10-05 02:01:06 -04:00
pprint-; ;
2005-08-21 14:25:05 -04:00
M: word class. drop ;
: see ( word -- )
2005-10-03 19:53:32 -04:00
[
dup (synopsis)
dup (see)
dup class.
methods.
2005-10-05 02:01:06 -04:00
newline
2005-10-03 19:53:32 -04:00
] with-pprint ;
: (apropos) ( substring -- seq )
2005-10-25 21:52:26 -04:00
all-words [ word-name [ subseq? ] completion? ] subset-with ;
: apropos ( substring -- )
2005-12-28 20:25:17 -05:00
(apropos) word-sort
[ [ synopsis ] keep simple-object terpri ] each ;