'see' cleanup
parent
1158ab413b
commit
8df790ec36
|
@ -93,6 +93,7 @@ sequences vectors words ;
|
||||||
"/library/compiler/alien/aliens.factor"
|
"/library/compiler/alien/aliens.factor"
|
||||||
|
|
||||||
"/library/syntax/prettyprint.factor"
|
"/library/syntax/prettyprint.factor"
|
||||||
|
"/library/syntax/synopsis.factor"
|
||||||
"/library/syntax/see.factor"
|
"/library/syntax/see.factor"
|
||||||
"/library/syntax/parser.factor"
|
"/library/syntax/parser.factor"
|
||||||
|
|
||||||
|
@ -296,6 +297,7 @@ sequences vectors words ;
|
||||||
"/library/syntax/parser.facts"
|
"/library/syntax/parser.facts"
|
||||||
"/library/syntax/parse-syntax.facts"
|
"/library/syntax/parse-syntax.facts"
|
||||||
"/library/syntax/prettyprint.facts"
|
"/library/syntax/prettyprint.facts"
|
||||||
|
"/library/syntax/synopsis.facts"
|
||||||
"/library/syntax/see.facts"
|
"/library/syntax/see.facts"
|
||||||
"/library/test/test.facts"
|
"/library/test/test.facts"
|
||||||
"/library/tools/word-tools.facts"
|
"/library/tools/word-tools.facts"
|
||||||
|
|
|
@ -4,103 +4,67 @@ IN: prettyprint
|
||||||
USING: arrays generic hashtables io kernel math namespaces
|
USING: arrays generic hashtables io kernel math namespaces
|
||||||
sequences strings styles words ;
|
sequences strings styles words ;
|
||||||
|
|
||||||
|
GENERIC: definition ( spec -- quot ? )
|
||||||
|
|
||||||
|
M: word definition drop f f ;
|
||||||
|
|
||||||
|
M: compound definition word-def t ;
|
||||||
|
|
||||||
|
M: generic definition "combination" word-prop t ;
|
||||||
|
|
||||||
|
M: method-spec definition first2 "methods" word-prop hash t ;
|
||||||
|
|
||||||
|
GENERIC: see ( spec -- )
|
||||||
|
|
||||||
|
GENERIC: declarations. ( obj -- )
|
||||||
|
|
||||||
|
M: object declarations. drop ;
|
||||||
|
|
||||||
: declaration. ( word prop -- )
|
: declaration. ( word prop -- )
|
||||||
tuck word-name word-prop [ pprint-word ] [ drop ] if ;
|
tuck word-name word-prop [ pprint-word ] [ drop ] if ;
|
||||||
|
|
||||||
: declarations. ( word -- )
|
M: word declarations.
|
||||||
{
|
{
|
||||||
POSTPONE: parsing
|
POSTPONE: parsing
|
||||||
POSTPONE: inline
|
POSTPONE: inline
|
||||||
POSTPONE: foldable
|
POSTPONE: foldable
|
||||||
} [ declaration. ] each-with ;
|
} [ declaration. ] each-with ;
|
||||||
|
|
||||||
: write-vocab ( vocab -- )
|
|
||||||
dup <vocab-link> presented associate styled-text ;
|
|
||||||
|
|
||||||
: in. ( word -- )
|
|
||||||
word-vocabulary [
|
|
||||||
H{ } <block \ IN: pprint-word write-vocab block;
|
|
||||||
] when* ;
|
|
||||||
|
|
||||||
: (synopsis) ( word -- )
|
|
||||||
dup in. dup definer pprint-word pprint-word ;
|
|
||||||
|
|
||||||
: comment. ( comment -- )
|
|
||||||
[ H{ { font-style italic } } [ text ] with-style ] when* ;
|
|
||||||
|
|
||||||
: stack-picture ( seq -- string )
|
|
||||||
[ [ % CHAR: \s , ] each ] "" make ;
|
|
||||||
|
|
||||||
: effect>string ( effect -- string )
|
|
||||||
[
|
|
||||||
"( " %
|
|
||||||
dup first stack-picture %
|
|
||||||
"-- " %
|
|
||||||
second stack-picture %
|
|
||||||
")" %
|
|
||||||
] "" make ;
|
|
||||||
|
|
||||||
: stack-effect ( word -- string )
|
|
||||||
dup "stack-effect" word-prop [ ] [
|
|
||||||
"infer-effect" word-prop dup [
|
|
||||||
[
|
|
||||||
dup integer? [ object <array> ] when
|
|
||||||
[ word-name ] map
|
|
||||||
] map effect>string
|
|
||||||
] when
|
|
||||||
] ?if ;
|
|
||||||
|
|
||||||
: synopsis ( word -- string )
|
|
||||||
[
|
|
||||||
0 margin set [
|
|
||||||
dup (synopsis) stack-effect comment.
|
|
||||||
] with-pprint
|
|
||||||
] string-out ;
|
|
||||||
|
|
||||||
GENERIC: (see) ( word -- )
|
|
||||||
|
|
||||||
M: word (see) drop ;
|
|
||||||
|
|
||||||
: pprint-; \ ; pprint-word ;
|
: pprint-; \ ; pprint-word ;
|
||||||
|
|
||||||
: see-body ( quot word -- )
|
: (see) ( spec -- )
|
||||||
H{ } <block
|
[
|
||||||
swap pprint-elements pprint-; declarations.
|
dup (synopsis)
|
||||||
block; ;
|
dup definition [
|
||||||
|
H{ } <block
|
||||||
|
pprint-elements pprint-; declarations.
|
||||||
|
block;
|
||||||
|
] [
|
||||||
|
2drop
|
||||||
|
] if newline
|
||||||
|
] with-pprint ;
|
||||||
|
|
||||||
M: compound (see)
|
M: method-spec see (see) ;
|
||||||
dup word-def swap see-body ;
|
|
||||||
|
|
||||||
: method. ( word class method -- )
|
GENERIC: see-methods* ( word -- seq )
|
||||||
\ M: pprint-word
|
|
||||||
>r pprint-word pprint-word r>
|
|
||||||
H{ } <block pprint-elements pprint-; block; ;
|
|
||||||
|
|
||||||
M: generic (see)
|
M: generic see-methods*
|
||||||
dup dup "combination" word-prop swap see-body
|
dup order [ swap 2array ] map-with ;
|
||||||
dup methods [ newline first2 method. ] each-with ;
|
|
||||||
|
|
||||||
GENERIC: class. ( word -- )
|
M: class see-methods*
|
||||||
|
dup implementors [ 2array ] map-with ;
|
||||||
|
|
||||||
: methods. ( class -- )
|
: see-methods ( word -- )
|
||||||
#! List all methods implemented for this class.
|
see-methods* [ see ] each ;
|
||||||
dup class? [
|
|
||||||
dup implementors [
|
|
||||||
newline
|
|
||||||
tuck dupd "methods" word-prop hash method.
|
|
||||||
] each-with
|
|
||||||
] [
|
|
||||||
drop
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
M: union class.
|
GENERIC: see-class* ( word -- )
|
||||||
newline
|
|
||||||
|
M: union see-class*
|
||||||
\ UNION: pprint-word
|
\ UNION: pprint-word
|
||||||
dup pprint-word
|
dup pprint-word
|
||||||
members pprint-elements pprint-; ;
|
members pprint-elements pprint-; ;
|
||||||
|
|
||||||
M: predicate class.
|
M: predicate see-class*
|
||||||
newline
|
|
||||||
\ PREDICATE: pprint-word
|
\ PREDICATE: pprint-word
|
||||||
dup superclass pprint-word
|
dup superclass pprint-word
|
||||||
dup pprint-word
|
dup pprint-word
|
||||||
|
@ -108,20 +72,18 @@ M: predicate class.
|
||||||
"definition" word-prop pprint-elements
|
"definition" word-prop pprint-elements
|
||||||
pprint-; block; ;
|
pprint-; block; ;
|
||||||
|
|
||||||
M: tuple-class class.
|
M: tuple-class see-class*
|
||||||
newline
|
|
||||||
\ TUPLE: pprint-word
|
\ TUPLE: pprint-word
|
||||||
dup pprint-word
|
dup pprint-word
|
||||||
"slot-names" word-prop [ text ] each
|
"slot-names" word-prop [ text ] each
|
||||||
pprint-; ;
|
pprint-; ;
|
||||||
|
|
||||||
M: word class. drop ;
|
M: word see-class* drop ;
|
||||||
|
|
||||||
: see ( word -- )
|
: see-class ( word -- )
|
||||||
[
|
[
|
||||||
dup (synopsis)
|
dup class?
|
||||||
dup (see)
|
[ see-class* newline ] [ drop ] if
|
||||||
dup class.
|
|
||||||
methods.
|
|
||||||
newline
|
|
||||||
] with-pprint ;
|
] with-pprint ;
|
||||||
|
|
||||||
|
M: word see dup (see) dup see-class see-methods ;
|
||||||
|
|
|
@ -5,55 +5,6 @@ HELP: declaration. "( word prop -- )"
|
||||||
{ $description "Prettyprints " { $snippet "prop" } " if " { $snippet "word" } " defines a word property string named by " { $snippet "prop" } "." }
|
{ $description "Prettyprints " { $snippet "prop" } " if " { $snippet "word" } " defines a word property string named by " { $snippet "prop" } "." }
|
||||||
$prettyprinting-note ;
|
$prettyprinting-note ;
|
||||||
|
|
||||||
HELP: in. "( word -- )"
|
|
||||||
{ $values { "word" "a word" } }
|
|
||||||
{ $description "Prettyprints a " { $snippet "IN:" } " declaration for the word." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: (synopsis) "( word -- )"
|
|
||||||
{ $values { "word" "a word" } }
|
|
||||||
{ $description "Prettyprints the prologue of the word's source definition." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: comment. "( string -- )"
|
|
||||||
{ $description "Prettyprints some text with the comment style." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: stack-effect "( word -- str )"
|
|
||||||
{ $values { "word" "a word" } { "str" "a string" } }
|
|
||||||
{ $description "Outputs the stack effect of a word, as a stack picture string. The stack effect is taken from either online help, or a cached inferred effect." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: synopsis "( word -- str )"
|
|
||||||
{ $values { "word" "a word" } { "str" "a string" } }
|
|
||||||
{ $description "Outputs a short string describing the word in Factor pseudo-code." }
|
|
||||||
{ $examples { $example "\\ append synopsis print" "IN: sequences : append ( seq1 seq2 -- seq )" } } ;
|
|
||||||
|
|
||||||
HELP: (see) "( word -- )"
|
|
||||||
{ $values { "word" "a word" } }
|
|
||||||
{ $contract "Prettyprints the definition of the word." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: see-body "( quot word -- )"
|
|
||||||
{ $values { "quot" "a quotation" } { "word" "a word" } }
|
|
||||||
{ $description "Prettyprints the elements of a quotation, followed by a semicolon (;) and any declarations for the word." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: method. "( word class method -- )"
|
|
||||||
{ $values { "word" "a generic word" } { "class" "a class word" } { "method" "a method quotation" } }
|
|
||||||
{ $description "Prettyprints a method definition." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: class. "( class -- )"
|
|
||||||
{ $values { "class" "a class word" } }
|
|
||||||
{ $contract "Prettyprints the class definition." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: methods. "( class -- )"
|
|
||||||
{ $values { "class" "a class word" } }
|
|
||||||
{ $contract "Prettyprints all methods defined on this class." }
|
|
||||||
$prettyprinting-note ;
|
|
||||||
|
|
||||||
HELP: see "( word -- )"
|
HELP: see "( word -- )"
|
||||||
{ $values { "word" "a word" } }
|
{ $values { "word" "a word" } }
|
||||||
{ $description "Prettyprints the definition of a word." } ;
|
{ $description "Prettyprints the definition of a word." } ;
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
! Copyright (C) 2006 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
IN: prettyprint
|
||||||
|
USING: arrays generic hashtables io kernel math namespaces
|
||||||
|
sequences styles words ;
|
||||||
|
|
||||||
|
PREDICATE: array method-spec
|
||||||
|
dup length 2 = [
|
||||||
|
first2 generic? >r class? r> and
|
||||||
|
] [
|
||||||
|
drop f
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
GENERIC: (synopsis) ( spec -- )
|
||||||
|
|
||||||
|
: write-vocab ( vocab -- )
|
||||||
|
dup <vocab-link> presented associate styled-text ;
|
||||||
|
|
||||||
|
: in. ( word -- )
|
||||||
|
word-vocabulary [
|
||||||
|
H{ } <block \ IN: pprint-word write-vocab block;
|
||||||
|
] when* ;
|
||||||
|
|
||||||
|
M: word (synopsis)
|
||||||
|
dup in. dup definer pprint-word pprint-word ;
|
||||||
|
|
||||||
|
M: method-spec (synopsis)
|
||||||
|
\ M: pprint-word [ pprint-word ] each ;
|
||||||
|
|
||||||
|
: comment. ( comment -- )
|
||||||
|
[ H{ { font-style italic } } [ text ] with-style ] when* ;
|
||||||
|
|
||||||
|
: stack-picture ( seq -- string )
|
||||||
|
[ [ % CHAR: \s , ] each ] "" make ;
|
||||||
|
|
||||||
|
: effect>string ( effect -- string )
|
||||||
|
[
|
||||||
|
"( " %
|
||||||
|
dup first stack-picture %
|
||||||
|
"-- " %
|
||||||
|
second stack-picture %
|
||||||
|
")" %
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
|
: stack-effect ( word -- string )
|
||||||
|
dup "stack-effect" word-prop [ ] [
|
||||||
|
"infer-effect" word-prop dup [
|
||||||
|
[
|
||||||
|
dup integer? [ object <array> ] when
|
||||||
|
[ word-name ] map
|
||||||
|
] map effect>string
|
||||||
|
] when
|
||||||
|
] ?if ;
|
||||||
|
|
||||||
|
: synopsis ( word -- string )
|
||||||
|
[
|
||||||
|
0 margin set [
|
||||||
|
dup (synopsis) stack-effect comment.
|
||||||
|
] with-pprint
|
||||||
|
] string-out ;
|
|
@ -0,0 +1,26 @@
|
||||||
|
IN: prettyprint
|
||||||
|
USING: help ;
|
||||||
|
|
||||||
|
HELP: in. "( word -- )"
|
||||||
|
{ $values { "word" "a word" } }
|
||||||
|
{ $description "Prettyprints a " { $snippet "IN:" } " declaration for the word." }
|
||||||
|
$prettyprinting-note ;
|
||||||
|
|
||||||
|
HELP: (synopsis) "( word -- )"
|
||||||
|
{ $values { "word" "a word" } }
|
||||||
|
{ $description "Prettyprints the prologue of the word's source definition." }
|
||||||
|
$prettyprinting-note ;
|
||||||
|
|
||||||
|
HELP: comment. "( string -- )"
|
||||||
|
{ $description "Prettyprints some text with the comment style." }
|
||||||
|
$prettyprinting-note ;
|
||||||
|
|
||||||
|
HELP: stack-effect "( word -- str )"
|
||||||
|
{ $values { "word" "a word" } { "str" "a string" } }
|
||||||
|
{ $description "Outputs the stack effect of a word, as a stack picture string. The stack effect is taken from either online help, or a cached inferred effect." }
|
||||||
|
$prettyprinting-note ;
|
||||||
|
|
||||||
|
HELP: synopsis "( word -- str )"
|
||||||
|
{ $values { "word" "a word" } { "str" "a string" } }
|
||||||
|
{ $description "Outputs a short string describing the word in Factor pseudo-code." }
|
||||||
|
{ $examples { $example "\\ append synopsis print" "IN: sequences : append ( seq1 seq2 -- seq )" } } ;
|
Loading…
Reference in New Issue