1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays io kernel namespaces parser prettyprint sequences
4 words assocs definitions generic quotations effects slots
5 continuations classes.tuple debugger combinators vocabs
6 help.stylesheet help.topics help.crossref help.markup sorting
7 classes vocabs.loader ;
10 GENERIC: word-help* ( word -- content )
12 : word-help ( word -- content )
13 dup "help" word-prop [ ] [
15 [ swap 2array 1array ] [ 2drop f ] if
18 : $predicate ( element -- )
19 { { "object" object } { "?" "a boolean" } } $values
21 "Tests if the object is an instance of the " ,
22 first "predicating" word-prop \ $link swap 2array ,
24 ] { } make $description ;
26 M: word word-help* drop f ;
28 M: predicate word-help* drop \ $predicate ;
30 : all-articles ( -- seq )
32 all-words [ word-help ] subset append ;
35 all-articles [ xref-article ] each ;
37 : error? ( word -- ? )
38 \ $error-description swap word-help elements empty? not ;
40 : sort-articles ( seq -- newseq )
41 [ dup article-title ] { } map>assoc sort-values keys ;
43 : all-errors ( -- seq )
44 all-words [ error? ] subset sort-articles ;
46 M: word article-name word-name ;
49 dup parsing? over symbol? or [
54 [ effect>string " " swap 3append ] when*
57 M: word article-content
59 \ $vocabulary over 2array ,
61 \ $related over 2array ,
62 dup get-global [ \ $value swap 2array , ] when*
63 \ $definition swap 2array ,
66 M: word article-parent "help-parent" word-prop ;
68 M: word set-article-parent swap "help-parent" set-word-prop ;
70 : $doc-path ( article -- )
71 help-path dup empty? [
76 "Parent topics: " write $links
85 dup article-title swap >link write-object
91 last-element off dup $title
92 article-content print-content nl ;
97 "No such vocabulary: " prepend throw
102 "The " write vocab-name write
103 " vocabulary does not define a main help article." print
104 "To define one, refer to \\ ABOUT: help" print
107 : ($index) ( articles -- )
108 sort-articles [ \ $subsection swap 2array ] map print-element ;
110 : $index ( element -- )
111 first call dup empty?
112 [ drop ] [ [ ($index) ] ($block) ] if ;
114 : $about ( element -- )
115 first vocab-help [ 1array $subsection ] when* ;
118 "This error has multiple delegates:" print
120 "Use \\ ... help to get help about a specific delegate." print ;
123 drop "No help for this error. " print ;
127 "Debugger commands:" print
129 ":s - data stack at error time" print
130 ":r - retain stack at error time" print
131 ":c - call stack at error time" print
132 ":edit - jump to source location (parse errors only)" print
134 ":get ( var -- value ) accesses variables at time of the error" print
135 ":vars - list all variables at error time" print ;
138 error get delegates [ error-help ] map [ ] subset
140 { [ dup empty? ] [ (:help-none) ] }
141 { [ dup length 1 = ] [ first help ] }
143 } cond (:help-debugger) ;
145 : remove-article ( name -- )
146 dup articles get key? [
148 dup articles get delete-at
151 : add-article ( article name -- )
152 [ remove-article ] keep
153 [ articles get set-at ] keep
156 : remove-word-help ( word -- )
157 dup word-help [ dup unxref-article ] when
158 f "help" set-word-prop ;
160 : set-word-help ( content word -- )
161 [ remove-word-help ] keep
162 [ swap "help" set-word-prop ] keep