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
|
2005-03-18 21:41:13 -05:00
|
|
|
presentation streams 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
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
: vocab. ( vocab -- ) dup vocab-attrs write-attr ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2004-12-29 03:35:46 -05:00
|
|
|
: prettyprint-IN: ( word -- )
|
2005-03-26 20:12:14 -05:00
|
|
|
\ IN: word-bl word-vocabulary vocab. terpri ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: prettyprint-prop ( word prop -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
tuck word-name word-prop [
|
2005-03-26 20:12:14 -05:00
|
|
|
" " write word.
|
2004-11-25 21:08:09 -05:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: prettyprint-plist ( word -- )
|
|
|
|
dup
|
|
|
|
\ parsing prettyprint-prop
|
|
|
|
\ inline prettyprint-prop ;
|
|
|
|
|
2005-03-18 19:38:27 -05:00
|
|
|
: comment-style
|
|
|
|
#! Feel free to redefine this!
|
|
|
|
[
|
|
|
|
[[ "ansi-fg" "0" ]]
|
|
|
|
[[ "ansi-bg" "2" ]]
|
|
|
|
[[ "fg" [ 255 0 0 ] ]]
|
|
|
|
] ;
|
|
|
|
|
|
|
|
: comment. ( comment -- ) comment-style write-attr ;
|
2005-02-07 13:14:55 -05:00
|
|
|
|
2005-03-23 22:49:40 -05:00
|
|
|
: infer-effect. ( effect -- )
|
2005-02-07 13:14:55 -05:00
|
|
|
[
|
|
|
|
"(" ,
|
|
|
|
2unlist >r [ " " , unparse , ] each r>
|
|
|
|
" --" ,
|
|
|
|
[ " " , unparse , ] each
|
|
|
|
" )" ,
|
|
|
|
] make-string comment. ;
|
|
|
|
|
2005-03-23 22:49:40 -05:00
|
|
|
: stack-effect. ( word -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
dup "stack-effect" word-prop [
|
2005-02-07 13:14:55 -05:00
|
|
|
[ CHAR: ( , , CHAR: ) , ] make-string
|
|
|
|
comment.
|
2005-02-07 12:16:39 -05:00
|
|
|
] [
|
2005-03-05 14:45:23 -05:00
|
|
|
"infer-effect" word-prop dup [
|
2005-02-07 12:16:39 -05:00
|
|
|
infer-effect.
|
|
|
|
] [
|
2005-02-07 13:14:55 -05:00
|
|
|
drop
|
2005-02-07 12:16:39 -05:00
|
|
|
] ifte
|
|
|
|
] ?ifte ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: documentation. ( indent word -- indent )
|
2005-03-05 14:45:23 -05:00
|
|
|
"documentation" word-prop [
|
2004-11-25 21:08:09 -05:00
|
|
|
"\n" split [
|
2005-02-07 13:14:55 -05:00
|
|
|
"#!" swap cat2 comment.
|
2004-11-25 21:08:09 -05:00
|
|
|
dup prettyprint-newline
|
|
|
|
] each
|
|
|
|
] when* ;
|
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
: definer. ( word -- ) dup definer word-bl word-bl ;
|
|
|
|
|
|
|
|
GENERIC: (see) ( word -- )
|
2004-12-12 23:49:44 -05:00
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
M: compound (see) ( word -- )
|
2005-03-23 22:49:40 -05:00
|
|
|
tab-size get dup indent swap
|
|
|
|
[ documentation. ] keep
|
2005-03-26 20:12:14 -05:00
|
|
|
[ word-def prettyprint-elements \ ; word. ] keep
|
|
|
|
prettyprint-plist terpri drop ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-03-23 22:49:40 -05:00
|
|
|
: prettyprint-M: ( indent -- indent )
|
2005-03-26 20:12:14 -05:00
|
|
|
\ M: word-bl tab-size get + ;
|
|
|
|
|
|
|
|
: prettyprint-; \ ; word. terpri ;
|
2005-03-23 22:49:40 -05:00
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
: see-method ( indent word class method -- indent )
|
|
|
|
>r >r >r prettyprint-M:
|
2005-03-26 20:12:14 -05:00
|
|
|
r> r> word-bl
|
|
|
|
word-bl
|
2004-12-29 18:01:23 -05:00
|
|
|
dup prettyprint-newline
|
2005-02-09 20:57:19 -05:00
|
|
|
r> prettyprint-elements
|
2005-03-26 20:12:14 -05:00
|
|
|
prettyprint-; tab-size get - ;
|
2005-02-24 20:52:17 -05:00
|
|
|
|
2005-03-23 22:49:40 -05:00
|
|
|
: see-generic ( word -- )
|
2005-03-26 20:12:14 -05:00
|
|
|
0 swap dup methods [
|
|
|
|
over >r uncons see-method r>
|
|
|
|
] each 2drop ;
|
|
|
|
|
|
|
|
M: generic (see) ( word -- ) see-generic ;
|
|
|
|
|
|
|
|
M: 2generic (see) ( word -- ) see-generic ;
|
|
|
|
|
|
|
|
M: word (see) drop ;
|
|
|
|
|
|
|
|
GENERIC: class.
|
|
|
|
|
|
|
|
M: union class.
|
|
|
|
\ UNION: word-bl
|
|
|
|
dup word-bl
|
|
|
|
0 swap "members" word-prop prettyprint-elements drop
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: complement class.
|
|
|
|
\ COMPLEMENT: word-bl
|
|
|
|
dup word-bl
|
|
|
|
"complement" word-prop word. terpri ;
|
|
|
|
|
|
|
|
M: builtin class.
|
|
|
|
\ BUILTIN: word-bl
|
|
|
|
dup word-bl
|
|
|
|
dup "builtin-type" word-prop unparse write " " write
|
|
|
|
0 swap "slots" word-prop prettyprint-elements drop
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: predicate class.
|
|
|
|
\ PREDICATE: word-bl
|
|
|
|
dup "superclass" word-prop word-bl
|
|
|
|
dup word-bl
|
|
|
|
tab-size get dup prettyprint-newline swap
|
|
|
|
"definition" word-prop prettyprint-elements drop
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: tuple-class class.
|
|
|
|
\ TUPLE: word-bl
|
|
|
|
dup word-bl
|
|
|
|
"slot-names" word-prop [ write " " write ] each
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: word class. drop ;
|
|
|
|
|
|
|
|
: see ( word -- )
|
2005-03-26 20:40:29 -05:00
|
|
|
dup prettyprint-IN: dup definer.
|
2005-03-26 20:12:14 -05:00
|
|
|
dup stack-effect. terpri dup (see) class. ;
|