factor/library/syntax/see.factor

133 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
USING: generic hashtables io kernel lists namespaces sequences
2005-06-27 03:47:22 -04:00
streams strings styles unparser words ;
2004-11-25 21:08:09 -05:00
: prettyprint-IN: ( word -- )
\ IN: unparse. bl word-vocabulary write terpri ;
2004-11-25 21:08:09 -05:00
: prettyprint-prop ( word prop -- )
tuck word-name word-prop [
bl unparse.
2004-11-25 21:08:09 -05:00
] [
drop
] ifte ;
: prettyprint-plist ( word -- )
dup
\ parsing prettyprint-prop
\ inline prettyprint-prop ;
: comment. ( comment -- )
[ [[ font-style italic ]] ] format ;
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
" )" %
2005-02-07 13:14:55 -05:00
] make-string comment. ;
2005-03-23 22:49:40 -05:00
: stack-effect. ( word -- )
dup "stack-effect" word-prop [
[ CHAR: ( , % CHAR: ) , ] make-string
2005-02-07 13:14:55 -05:00
comment.
] [
"infer-effect" word-prop 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-prop [
2004-11-25 21:08:09 -05:00
"\n" split [
2005-05-18 16:26:22 -04:00
"#!" swap append comment.
2004-11-25 21:08:09 -05:00
dup prettyprint-newline
] each
] when* ;
: definer. ( word -- ) dup definer unparse. bl unparse. bl ;
GENERIC: (see) ( word -- )
M: compound (see) ( word -- )
2005-03-23 22:49:40 -05:00
tab-size get dup indent swap
[ documentation. ] keep
[ word-def prettyprint-elements \ ; unparse. ] keep
prettyprint-plist terpri drop ;
2004-11-25 21:08:09 -05:00
2005-04-10 18:58:30 -04:00
: prettyprint-M: ( -- indent )
\ M: unparse. bl tab-size get ;
: prettyprint-; \ ; unparse. terpri ;
2005-03-23 22:49:40 -05:00
2005-04-10 18:58:30 -04:00
: method. ( word [[ class method ]] -- )
uncons >r >r >r prettyprint-M: r> r> unparse. bl unparse. bl
2005-04-10 18:58:30 -04:00
dup prettyprint-newline r> prettyprint-elements
prettyprint-; drop ;
M: generic (see) ( word -- )
tab-size get dup indent [
one-line on
over "picker" word-prop prettyprint* bl
over "dispatcher" word-prop prettyprint* bl
] with-scope
drop
\ ; unparse. terpri
dup methods [ method. ] each-with ;
M: word (see) drop ;
GENERIC: class.
M: union class.
\ UNION: unparse. bl
dup unparse. bl
0 swap "members" word-prop prettyprint-elements drop
prettyprint-; ;
M: complement class.
\ COMPLEMENT: unparse. bl
dup unparse. bl
"complement" word-prop unparse. terpri ;
M: builtin class.
\ BUILTIN: unparse. bl
dup unparse. bl
dup "builtin-type" word-prop unparse write bl
0 swap "slots" word-prop prettyprint-elements drop
prettyprint-; ;
M: predicate class.
\ PREDICATE: unparse. bl
dup "superclass" word-prop unparse. bl
dup unparse. bl
tab-size get dup prettyprint-newline swap
"definition" word-prop prettyprint-elements drop
prettyprint-; ;
M: tuple-class class.
\ TUPLE: unparse. bl
dup unparse. bl
"slot-names" word-prop [ write bl ] each
prettyprint-; ;
M: word class. drop ;
: see ( word -- )
2005-03-26 20:40:29 -05:00
dup prettyprint-IN: dup definer.
dup stack-effect. terpri dup (see) class. ;
2005-04-10 18:58:30 -04:00
: methods. ( class -- )
#! List all methods implemented for this class.
dup class.
dup implementors [
dup prettyprint-IN:
[ "methods" word-prop hash* ] keep swap method.
] each-with ;