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-02-06 00:21:26 -05:00
|
|
|
USING: generic kernel lists math namespaces stdio strings
|
|
|
|
presentation unparser words ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
! Prettyprinting words
|
2004-12-29 03:35:46 -05:00
|
|
|
: vocab-actions ( search -- list )
|
|
|
|
[
|
2005-01-13 19:49:47 -05:00
|
|
|
[[ "Words" "words." ]]
|
|
|
|
[[ "Use" "\"use\" cons@" ]]
|
|
|
|
[[ "In" "\"in\" set" ]]
|
2004-12-29 03:35:46 -05:00
|
|
|
] ;
|
|
|
|
|
|
|
|
: vocab-attrs ( vocab -- attrs )
|
|
|
|
#! Words without a vocabulary do not get a link or an action
|
|
|
|
#! popup.
|
|
|
|
unparse vocab-actions <actions> "actions" swons unit ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: prettyprint-vocab ( vocab -- )
|
|
|
|
dup vocab-attrs write-attr ;
|
|
|
|
|
2004-12-29 03:35:46 -05:00
|
|
|
: prettyprint-IN: ( word -- )
|
2004-12-29 18:01:23 -05:00
|
|
|
\ IN: prettyprint* " " write
|
|
|
|
word-vocabulary prettyprint-vocab " " write ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: prettyprint-: ( indent -- indent )
|
2004-12-29 18:01:23 -05:00
|
|
|
\ : prettyprint* " " write
|
2005-02-06 00:21:26 -05:00
|
|
|
tab-size get + ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: prettyprint-; ( indent -- indent )
|
2004-12-12 23:49:44 -05:00
|
|
|
\ ; prettyprint*
|
2005-02-06 00:21:26 -05:00
|
|
|
tab-size get - ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: prettyprint-prop ( word prop -- )
|
|
|
|
tuck word-name word-property [
|
2004-12-29 18:01:23 -05:00
|
|
|
" " write prettyprint-1
|
2004-11-25 21:08:09 -05:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: prettyprint-plist ( word -- )
|
|
|
|
dup
|
|
|
|
\ parsing prettyprint-prop
|
|
|
|
\ inline prettyprint-prop ;
|
|
|
|
|
|
|
|
: prettyprint-comment ( comment -- )
|
|
|
|
"comments" style write-attr ;
|
|
|
|
|
2005-02-07 12:16:39 -05:00
|
|
|
: infer-effect. ( effect -- )
|
|
|
|
0 swap
|
|
|
|
" ( " prettyprint-comment
|
|
|
|
2unlist >r [ prettyprint-element ] each r>
|
|
|
|
"-- " write
|
|
|
|
[ prettyprint-element ] each
|
|
|
|
")" prettyprint-comment
|
|
|
|
drop ;
|
|
|
|
|
2004-11-25 21:08:09 -05:00
|
|
|
: stack-effect. ( word -- )
|
2005-02-07 12:16:39 -05:00
|
|
|
dup "stack-effect" word-property [
|
2004-11-25 21:08:09 -05:00
|
|
|
" " write
|
|
|
|
[ CHAR: ( , , CHAR: ) , ] make-string prettyprint-comment
|
2005-02-07 12:16:39 -05:00
|
|
|
] [
|
|
|
|
"infer-effect" word-property dup [
|
|
|
|
infer-effect.
|
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] ifte
|
|
|
|
] ?ifte ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: documentation. ( indent word -- indent )
|
2005-02-07 12:16:39 -05:00
|
|
|
"documentation" word-property [
|
2004-11-25 21:08:09 -05:00
|
|
|
"\n" split [
|
|
|
|
"#!" swap cat2 prettyprint-comment
|
|
|
|
dup prettyprint-newline
|
|
|
|
] each
|
|
|
|
] when* ;
|
|
|
|
|
|
|
|
: prettyprint-docs ( indent word -- indent )
|
|
|
|
[
|
|
|
|
stack-effect. dup prettyprint-newline
|
|
|
|
] keep documentation. ;
|
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
: prettyprint-M: ( indent -- indent )
|
2005-02-06 00:21:26 -05:00
|
|
|
\ M: prettyprint-1 " " write tab-size get + ;
|
2004-12-12 23:49:44 -05:00
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
GENERIC: see ( word -- )
|
2004-12-12 23:49:44 -05:00
|
|
|
|
|
|
|
M: compound see ( word -- )
|
2004-12-29 18:01:23 -05:00
|
|
|
dup prettyprint-IN:
|
2004-12-29 03:35:46 -05:00
|
|
|
0 prettyprint-: swap
|
2004-12-12 23:49:44 -05:00
|
|
|
[ prettyprint-1 ] keep
|
2004-11-25 21:08:09 -05:00
|
|
|
[ prettyprint-docs ] keep
|
2005-02-06 00:21:26 -05:00
|
|
|
[
|
|
|
|
word-parameter [ prettyprint-element ] each
|
|
|
|
prettyprint-;
|
|
|
|
] keep
|
2004-11-25 21:08:09 -05:00
|
|
|
prettyprint-plist prettyprint-newline ;
|
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
: see-method ( indent word class method -- indent )
|
|
|
|
>r >r >r prettyprint-M:
|
2004-12-30 02:40:14 -05:00
|
|
|
r> r> prettyprint-1 " " write
|
|
|
|
prettyprint-1 " " write
|
2004-12-29 18:01:23 -05:00
|
|
|
dup prettyprint-newline
|
2005-02-06 00:21:26 -05:00
|
|
|
r> [ prettyprint-element ] each
|
2004-12-29 18:01:23 -05:00
|
|
|
prettyprint-;
|
|
|
|
terpri ;
|
|
|
|
|
|
|
|
M: generic see ( word -- )
|
|
|
|
dup prettyprint-IN:
|
|
|
|
0 swap
|
|
|
|
dup "definer" word-property prettyprint-1 " " write
|
|
|
|
dup prettyprint-1 terpri
|
|
|
|
dup methods [ over >r uncons see-method r> ] each 2drop ;
|
|
|
|
|
2004-12-12 23:49:44 -05:00
|
|
|
M: primitive see ( word -- )
|
2004-12-29 03:35:46 -05:00
|
|
|
dup prettyprint-IN:
|
|
|
|
"PRIMITIVE: " write dup prettyprint-1 stack-effect. terpri ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2004-12-12 23:49:44 -05:00
|
|
|
M: symbol see ( word -- )
|
2004-12-29 03:35:46 -05:00
|
|
|
dup prettyprint-IN:
|
2004-12-29 18:01:23 -05:00
|
|
|
\ SYMBOL: prettyprint-1 " " write . ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2004-12-12 23:49:44 -05:00
|
|
|
M: undefined see ( word -- )
|
2004-12-29 03:35:46 -05:00
|
|
|
dup prettyprint-IN:
|
2004-12-29 18:01:23 -05:00
|
|
|
\ DEFER: prettyprint-1 " " write . ;
|