1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays io kernel namespaces parser prettyprint
4 sequences words assocs definitions generic quotations effects
5 slots 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 ] filter 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? ] filter sort-articles ;
46 M: word article-name name>> ;
49 dup [ parsing-word? ] [ symbol? ] bi or [
53 [ stack-effect [ effect>string " " prepend ] [ "" ] if* ] bi
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* ;
117 : :help-debugger ( -- )
119 "Debugger commands:" print
121 ":s - data stack at error time" print
122 ":r - retain stack at error time" print
123 ":c - call stack at error time" print
124 ":edit - jump to source location (parse errors only)" print
126 ":get ( var -- value ) accesses variables at time of the error" print
127 ":vars - list all variables at error time" print ;
130 error get error-help [ help ] [ "No help for this error. " print ] if*
133 : remove-article ( name -- )
134 dup articles get key? [
136 dup articles get delete-at
139 : add-article ( article name -- )
140 [ remove-article ] keep
141 [ articles get set-at ] keep
144 : remove-word-help ( word -- )
145 dup word-help [ dup unxref-article ] when
146 f "help" set-word-prop ;
148 : set-word-help ( content word -- )
149 [ remove-word-help ] keep
150 [ swap "help" set-word-prop ] keep