factor/library/syntax/see.factor

129 lines
3.2 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-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
: vocab-actions ( search -- list )
[
[[ "Words" "words." ]]
[[ "Use" "\"use\" cons@" ]]
[[ "In" "\"in\" set" ]]
] ;
: 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 ;
: prettyprint-IN: ( word -- )
2005-02-09 20:57:19 -05:00
\ IN: prettyprint-word " " write
2004-12-29 18:01:23 -05:00
word-vocabulary prettyprint-vocab " " write ;
2004-11-25 21:08:09 -05:00
: prettyprint-: ( indent -- indent )
2005-02-09 20:57:19 -05:00
\ : prettyprint-word " " write
2005-02-06 00:21:26 -05:00
tab-size get + ;
2004-11-25 21:08:09 -05:00
: prettyprint-; ( indent -- indent )
2005-02-09 20:57:19 -05:00
\ ; prettyprint-word
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 [
2005-02-09 20:57:19 -05:00
" " write prettyprint-word
2004-11-25 21:08:09 -05:00
] [
drop
] ifte ;
: prettyprint-plist ( word -- )
dup
\ parsing prettyprint-prop
\ inline prettyprint-prop ;
2005-02-07 13:14:55 -05:00
: comment. ( comment -- ) "comments" style write-attr ;
: infer-effect. ( indent effect -- indent )
" " write
[
"(" ,
2unlist >r [ " " , unparse , ] each r>
" --" ,
[ " " , unparse , ] each
" )" ,
] make-string comment. ;
: stack-effect. ( indent word -- indent )
dup "stack-effect" word-property [
2004-11-25 21:08:09 -05:00
" " write
2005-02-07 13:14:55 -05:00
[ CHAR: ( , , CHAR: ) , ] make-string
comment.
] [
"infer-effect" word-property dup [
infer-effect.
] [
2005-02-07 13:14:55 -05:00
drop
] ifte
] ?ifte ;
2004-11-25 21:08:09 -05:00
: documentation. ( indent word -- indent )
"documentation" word-property [
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* ;
: 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-09 20:57:19 -05:00
\ M: prettyprint-word " " write tab-size get + ;
2004-12-29 18:01:23 -05:00
GENERIC: see ( word -- )
M: compound see ( word -- )
2004-12-29 18:01:23 -05:00
dup prettyprint-IN:
0 prettyprint-: swap
2005-02-09 20:57:19 -05:00
[ prettyprint-word ] keep
2004-11-25 21:08:09 -05:00
[ prettyprint-docs ] keep
2005-02-06 00:21:26 -05:00
[
2005-02-09 20:57:19 -05:00
word-parameter prettyprint-elements
2005-02-06 00:21:26 -05:00
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:
2005-02-09 20:57:19 -05:00
r> r> prettyprint-word " " write
prettyprint-word " " write
2004-12-29 18:01:23 -05:00
dup prettyprint-newline
2005-02-09 20:57:19 -05:00
r> prettyprint-elements
2004-12-29 18:01:23 -05:00
prettyprint-;
terpri ;
M: generic see ( word -- )
dup prettyprint-IN:
0 swap
2005-02-09 20:57:19 -05:00
dup "definer" word-property prettyprint-word " " write
dup prettyprint-word terpri
2004-12-29 18:01:23 -05:00
dup methods [ over >r uncons see-method r> ] each 2drop ;
M: primitive see ( word -- )
dup prettyprint-IN:
2005-02-09 20:57:19 -05:00
"PRIMITIVE: " write dup prettyprint-word stack-effect.
terpri ;
2004-11-25 21:08:09 -05:00
M: symbol see ( word -- )
dup prettyprint-IN:
2005-02-09 20:57:19 -05:00
\ SYMBOL: prettyprint-word " " write . ;
2004-11-25 21:08:09 -05:00
M: undefined see ( word -- )
dup prettyprint-IN:
2005-02-09 20:57:19 -05:00
\ DEFER: prettyprint-word " " write . ;