factor/library/syntax/see.factor

78 lines
2.0 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-08-21 01:17:37 -04:00
USING: generic io kernel lists namespaces sequences styles words ;
2004-11-25 21:08:09 -05:00
2005-08-21 01:17:37 -04:00
: declaration. ( word prop -- )
tuck word-name word-prop
[ bl pprint-object ] [ drop ] ifte ;
2004-11-25 21:08:09 -05:00
2005-08-21 01:17:37 -04:00
: declarations. ( word -- )
[
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
: 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 01:17:37 -04:00
: stack-picture ( seq -- string )
[ [ word-name % " " % ] each ] make-string ;
2005-08-21 01:17:37 -04:00
: effect>string ( effect -- string )
2unseq stack-picture >r stack-picture "-- " r> append3 ;
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-08-21 01:17:37 -04:00
: stack-effect. ( string -- )
[ bl "( " swap ")" append3 comment. ] when* ;
2005-03-23 22:49:40 -05:00
2005-08-21 01:17:37 -04:00
: in. ( word -- )
<block \ IN: pprint-object bl word-vocabulary f text block>
t newline ;
2005-08-21 01:17:37 -04:00
: definer. ( word -- )
dup definer pprint-object bl
dup pprint-object
stack-effect stack-effect.
f newline ;
2005-08-21 01:17:37 -04:00
GENERIC: (see) ( word -- )
2005-08-21 01:17:37 -04:00
M: word (see) definer. t newline ;
2005-08-21 01:17:37 -04:00
: documentation. ( word -- )
"documentation" word-prop [
"\n" split [ "#!" swap append comment. t newline ] each
] when* ;
2005-08-21 01:17:37 -04:00
: see-body ( quot word -- )
dup definer. <block dup documentation. swap pprint-elements
\ ; pprint-object declarations. block> ;
2005-08-21 01:17:37 -04:00
M: compound (see)
dup word-def swap see-body t newline ;
2005-08-21 01:17:37 -04:00
: method. ( word [[ class method ]] -- )
<block
\ M: pprint-object bl
unswons pprint-object bl
swap pprint-object t newline
pprint-elements \ ; pprint-object
block> t newline ;
M: generic (see)
<block
dup dup { "picker" "combination" } [ word-prop ] map-with
swap see-body block> t newline
dup methods [ method. ] each-with ;
: see ( word -- )
2005-08-21 01:17:37 -04:00
[ dup in. (see) ] with-pprint ;