2004-11-25 21:08:09 -05:00
|
|
|
! :folding=indent:collapseFolds=1:
|
|
|
|
|
|
|
|
! $Id$
|
|
|
|
!
|
|
|
|
! Copyright (C) 2003, 2004 Slava Pestov.
|
|
|
|
!
|
|
|
|
! Redistribution and use in source and binary forms, with or without
|
|
|
|
! modification, are permitted provided that the following conditions are met:
|
|
|
|
!
|
|
|
|
! 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer.
|
|
|
|
!
|
|
|
|
! 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer in the documentation
|
|
|
|
! and/or other materials provided with the distribution.
|
|
|
|
!
|
|
|
|
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
IN: prettyprint
|
2004-12-12 23:49:44 -05:00
|
|
|
USE: generic
|
2004-12-10 19:29:07 -05:00
|
|
|
USE: kernel
|
2004-11-25 21:08:09 -05:00
|
|
|
USE: lists
|
|
|
|
USE: math
|
|
|
|
USE: stdio
|
|
|
|
USE: strings
|
|
|
|
USE: presentation
|
|
|
|
USE: unparser
|
|
|
|
USE: words
|
|
|
|
|
|
|
|
! Prettyprinting words
|
2004-12-29 03:35:46 -05:00
|
|
|
: 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 ;
|
|
|
|
|
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
|
2004-11-25 21:08:09 -05:00
|
|
|
tab-size + ;
|
|
|
|
|
|
|
|
: prettyprint-; ( indent -- indent )
|
2004-12-12 23:49:44 -05:00
|
|
|
\ ; prettyprint*
|
2004-11-25 21:08:09 -05:00
|
|
|
tab-size - ;
|
|
|
|
|
|
|
|
: 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 ;
|
|
|
|
|
|
|
|
: stack-effect. ( word -- )
|
|
|
|
stack-effect [
|
|
|
|
" " write
|
|
|
|
[ CHAR: ( , , CHAR: ) , ] make-string prettyprint-comment
|
|
|
|
] when* ;
|
|
|
|
|
|
|
|
: documentation. ( indent word -- indent )
|
|
|
|
documentation [
|
|
|
|
"\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 )
|
|
|
|
\ M: prettyprint-1 " " write tab-size + ;
|
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
|
|
|
|
[ word-parameter prettyprint-list prettyprint-; ] keep
|
|
|
|
prettyprint-plist prettyprint-newline ;
|
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
: see-method ( indent word class method -- indent )
|
|
|
|
>r >r >r prettyprint-M:
|
|
|
|
r> prettyprint-1 " " write
|
|
|
|
r> prettyprint-1 " " write
|
|
|
|
dup prettyprint-newline
|
|
|
|
r> prettyprint-list
|
|
|
|
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 . ;
|