factor/library/syntax/see.factor

136 lines
3.1 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-09-14 00:37:50 -04:00
USING: 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 -- )
[
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 )
2005-09-14 00:37:50 -04:00
dup integer? [ object <repeated> ] when
[ word-name % " " % ] each ;
2005-08-21 01:17:37 -04:00
: effect>string ( effect -- string )
[
" " %
dup first stack-picture%
"-- " %
second stack-picture%
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-08-21 01:17:37 -04:00
: stack-effect. ( string -- )
2005-08-29 01:00:55 -04:00
[ "(" swap ")" append3 comment. ] when* ;
2005-03-23 22:49:40 -05:00
2005-08-21 01:17:37 -04:00
: in. ( word -- )
2005-10-03 19:53:32 -04:00
<block \ IN: pprint-word word-vocabulary f text block; ;
2005-10-03 19:53:32 -04:00
: (synopsis) ( word -- )
dup in.
2005-08-29 01:00:55 -04:00
dup definer pprint-word
dup pprint-word
2005-08-29 01:00:55 -04:00
stack-effect stack-effect. ;
2005-10-10 21:12:53 -04:00
: synopsis ( word -- string )
#! Output a brief description of the word in question.
[ 0 margin set [ (synopsis) ] 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 ;
2005-08-21 01:17:37 -04:00
: documentation. ( word -- )
"documentation" word-prop [
2005-08-29 01:00:55 -04:00
"\n" split [ "#!" swap append comment. newline ] each
2005-08-21 01:17:37 -04:00
] when* ;
: pprint-; \ ; pprint-word ;
2005-08-21 14:25:05 -04:00
2005-08-21 01:17:37 -04:00
: see-body ( quot word -- )
2005-10-03 19:53:32 -04:00
<block dup documentation. 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
"slot-names" word-prop [ f 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 -- )
#! List all words that contain a string.
(apropos) [
"IN: " write dup word-vocabulary write " " write .
] each ;