1 ! Copyright (C) 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: arrays errors generic hashtables io kernel math
5 namespaces parser prettyprint prettyprint-internals sequences
8 : reload ( defspec -- )
9 where first [ run-file ] when* ;
15 : edit-location ( file line -- )
17 edit-hook get [ call ] [ <no-edit-hook> throw ] if* ;
19 : edit-file ( file -- ) ?resource-path 0 edit-location ;
25 "Not from a source file" throw
28 : write-vocab ( vocab -- )
29 dup <vocab-link> presented associate styled-text ;
33 H{ } clone <flow \ IN: pprint-word write-vocab block>
36 : comment. ( string -- )
37 [ H{ { font-style italic } } styled-text ] when* ;
41 dup definer pprint-word
43 stack-effect [ effect>string comment. ] when* ;
45 M: method-spec synopsis*
46 \ M: pprint-word [ pprint-word ] each ;
48 : synopsis ( defspec -- str )
49 [ 0 margin set [ synopsis* ] with-pprint ] string-out ;
51 M: word summary synopsis ;
53 GENERIC: definition ( spec -- quot ? )
55 M: word definition drop f f ;
57 M: compound definition word-def t ;
59 M: generic definition "combination" word-prop t ;
61 M: method-spec definition first2 method method-def t ;
63 GENERIC: declarations. ( obj -- )
65 M: object declarations. drop ;
67 : declaration. ( word prop -- )
68 tuck word-name word-prop [ pprint-word ] [ drop ] if ;
75 } [ declaration. ] each-with ;
77 : pprint-; \ ; pprint-word ;
84 pprint-elements pprint-; declarations.
93 GENERIC: see-class* ( word -- )
98 members pprint-elements pprint-; ;
100 M: predicate see-class*
101 \ PREDICATE: pprint-word
102 dup superclass pprint-word
105 "definition" word-prop pprint-elements
108 M: tuple-class see-class*
111 "slot-names" word-prop [ text ] each
114 M: word see-class* drop ;
116 : see-class ( word -- )
117 dup class? over builtin? not and [
118 terpri [ see-class* ] with-pprint terpri
123 : see-subdefs ( word -- ) subdefs [ terpri see ] each ;
125 M: word see dup (see) dup see-class see-subdefs ;
127 M: link where link-name article article-loc ;
130 \ ARTICLE: pprint-word
131 dup link-name pprint*
132 article-title pprint* ;
134 M: link definition article-content t ;
138 PREDICATE: link word-link link-name word? ;
140 M: word-link where link-name "help-loc" word-prop ;
142 M: word-link synopsis*
144 link-name dup pprint-word
145 stack-effect effect>string comment. ;
147 M: word-link definition
148 link-name "help" word-prop t ;
150 M: link forget link-name remove-article ;
152 M: word-link forget f "help" set-word-prop ;