1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays io io.styles kernel namespaces parser
4 prettyprint sequences words assocs definitions generic
5 quotations effects slots continuations classes.tuple debugger
6 combinators vocabs help.stylesheet help.topics help.crossref
7 help.markup sorting 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 ;
34 : orphan-articles ( -- seq )
36 [ article-parent not ] filter ;
39 all-articles [ xref-article ] each ;
41 : error? ( word -- ? )
42 \ $error-description swap word-help elements empty? not ;
44 : sort-articles ( seq -- newseq )
45 [ dup article-title ] { } map>assoc sort-values keys ;
47 : all-errors ( -- seq )
48 all-words [ error? ] filter sort-articles ;
50 M: word article-name name>> ;
53 dup [ parsing-word? ] [ symbol? ] bi or [
57 [ stack-effect [ effect>string " " prepend ] [ "" ] if* ] bi
61 M: word article-content
63 \ $vocabulary over 2array ,
65 \ $related over 2array ,
66 dup get-global [ \ $value swap 2array , ] when*
67 \ $definition swap 2array ,
70 M: word article-parent "help-parent" word-prop ;
72 M: word set-article-parent swap "help-parent" set-word-prop ;
74 : $doc-path ( article -- )
75 help-path dup empty? [
80 "Parent topics: " write $links
89 dup article-title swap >link write-object
95 last-element off dup $title
96 article-content print-content nl ;
101 "No such vocabulary: " prepend throw
106 "The " write vocab-name write
107 " vocabulary does not define a main help article." print
108 "To define one, refer to \\ ABOUT: help" print
111 : ($index) ( articles -- )
112 sort-articles [ \ $subsection swap 2array ] map print-element ;
114 : $index ( element -- )
115 first call dup empty?
116 [ drop ] [ ($index) ] if ;
118 : $about ( element -- )
119 first vocab-help [ 1array $subsection ] when* ;
121 : :help-debugger ( -- )
123 "Debugger commands:" print
125 ":s - data stack at error time" print
126 ":r - retain stack at error time" print
127 ":c - call stack at error time" print
128 ":edit - jump to source location (parse errors only)" print
130 ":get ( var -- value ) accesses variables at time of the error" print
131 ":vars - list all variables at error time" print ;
134 error get error-help [ help ] [ "No help for this error. " print ] if*
137 : remove-article ( name -- )
138 dup articles get key? [
140 dup articles get delete-at
143 : add-article ( article name -- )
144 [ remove-article ] keep
145 [ articles get set-at ] keep
148 : remove-word-help ( word -- )
149 dup word-help [ dup unxref-article ] when
150 f "help" set-word-prop ;
152 : set-word-help ( content word -- )
153 [ remove-word-help ] keep
154 [ swap "help" set-word-prop ] keep