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
|
|
|
|
sequences styles words ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: declaration. ( word prop -- )
|
2005-08-29 01:00:55 -04:00
|
|
|
tuck word-name word-prop [ pprint-word ] [ drop ] ifte ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: declarations. ( word -- )
|
2005-08-12 18:02:03 -04:00
|
|
|
[
|
|
|
|
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
|
|
|
|
2005-07-17 14:48:55 -04:00
|
|
|
: comment. ( comment -- )
|
2005-08-21 01:17:37 -04:00
|
|
|
[ [[ font-style italic ]] ] text ;
|
2005-02-07 13:14:55 -05:00
|
|
|
|
2005-08-21 20:50:14 -04:00
|
|
|
: stack-picture% ( seq -- string )
|
2005-09-14 00:37:50 -04:00
|
|
|
dup integer? [ object <repeated> ] when
|
2005-08-21 20:50:14 -04:00
|
|
|
[ word-name % " " % ] each ;
|
2004-12-12 23:49:44 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: effect>string ( effect -- string )
|
2005-08-21 20:50:14 -04:00
|
|
|
[
|
|
|
|
" " %
|
|
|
|
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
|
|
|
|
] ?ifte ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
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-08-29 01:00:55 -04:00
|
|
|
<block \ IN: pprint-word word-vocabulary f text block;
|
|
|
|
newline ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: definer. ( word -- )
|
2005-08-29 01:00:55 -04:00
|
|
|
dup definer pprint-word
|
2005-08-21 20:50:14 -04:00
|
|
|
dup pprint-word
|
2005-08-29 01:00:55 -04:00
|
|
|
stack-effect stack-effect. ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
GENERIC: (see) ( word -- )
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-29 01:00:55 -04:00
|
|
|
M: word (see) definer. newline ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
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* ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 20:50:14 -04:00
|
|
|
: 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
|
2005-08-21 20:50:14 -04:00
|
|
|
pprint-; declarations. block; ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
M: compound (see)
|
2005-08-29 01:00:55 -04:00
|
|
|
dup word-def swap see-body newline ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: method. ( word [[ class method ]] -- )
|
2005-08-29 01:00:55 -04:00
|
|
|
\ M: pprint-word
|
|
|
|
unswons pprint-word
|
|
|
|
swap pprint-word
|
2005-08-21 20:50:14 -04:00
|
|
|
<block pprint-elements pprint-;
|
2005-08-29 01:00:55 -04:00
|
|
|
block; newline ;
|
2005-08-21 01:17:37 -04:00
|
|
|
|
|
|
|
M: generic (see)
|
2005-09-01 01:20:43 -04:00
|
|
|
dup dup "combination" word-prop swap see-body newline
|
2005-08-21 01:17:37 -04:00
|
|
|
dup methods [ method. ] each-with ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 14:25:05 -04:00
|
|
|
GENERIC: class. ( word -- )
|
|
|
|
|
|
|
|
: methods. ( class -- )
|
|
|
|
#! List all methods implemented for this class.
|
2005-09-16 02:39:33 -04:00
|
|
|
dup class? [
|
2005-08-21 14:25:05 -04:00
|
|
|
dup implementors [
|
|
|
|
dup in. tuck "methods" word-prop hash* method.
|
|
|
|
] each-with
|
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
M: union class.
|
2005-08-29 01:00:55 -04:00
|
|
|
\ UNION: pprint-word
|
|
|
|
dup pprint-word
|
2005-09-16 02:39:33 -04:00
|
|
|
members pprint-elements pprint-; newline ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: predicate class.
|
2005-08-29 01:00:55 -04:00
|
|
|
\ PREDICATE: pprint-word
|
2005-09-16 02:39:33 -04:00
|
|
|
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-08-29 01:00:55 -04:00
|
|
|
pprint-; block; newline ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: tuple-class class.
|
2005-08-29 01:00:55 -04:00
|
|
|
\ TUPLE: pprint-word
|
|
|
|
dup pprint-word
|
|
|
|
"slot-names" word-prop [ f text ] each
|
|
|
|
pprint-; newline ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: word class. drop ;
|
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
: see ( word -- )
|
2005-08-21 14:25:05 -04:00
|
|
|
[ dup in. dup (see) dup class. methods. ] with-pprint ;
|
2005-08-31 21:06:13 -04:00
|
|
|
|
|
|
|
: (apropos) ( substring -- seq )
|
|
|
|
vocabs [
|
|
|
|
words [ word-name subseq? ] subset-with
|
|
|
|
] map-with concat ;
|
|
|
|
|
|
|
|
: apropos ( substring -- )
|
|
|
|
#! List all words that contain a string.
|
|
|
|
(apropos) [
|
|
|
|
"IN: " write dup word-vocabulary write " " write .
|
|
|
|
] each ;
|