| 
									
										
										
										
											2008-02-08 02:08:52 -05:00
										 |  |  | ! Copyright (C) 2005, 2008 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-09-10 21:07:00 -04:00
										 |  |  | USING: accessors arrays io io.styles kernel namespaces make | 
					
						
							| 
									
										
										
										
											2008-12-17 19:10:01 -05:00
										 |  |  | parser prettyprint sequences words words.symbol assocs | 
					
						
							|  |  |  | definitions generic quotations effects slots continuations | 
					
						
							|  |  |  | classes.tuple debugger combinators vocabs help.stylesheet | 
					
						
							|  |  |  | help.topics help.crossref help.markup sorting classes | 
					
						
							|  |  |  | vocabs.loader ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: help | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: word-help* ( word -- content )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : word-help ( word -- content )
 | 
					
						
							|  |  |  |     dup "help" word-prop [ ] [ | 
					
						
							|  |  |  |         dup word-help* dup
 | 
					
						
							|  |  |  |         [ swap 2array 1array ] [ 2drop f ] if
 | 
					
						
							|  |  |  |     ] ?if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-12 00:32:35 -05:00
										 |  |  | : $predicate ( element -- )
 | 
					
						
							|  |  |  |     { { "object" object } { "?" "a boolean" } } $values | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         "Tests if the object is an instance of the " , | 
					
						
							| 
									
										
										
										
											2008-11-22 04:22:19 -05:00
										 |  |  |         first "predicating" word-prop <$link> , | 
					
						
							| 
									
										
										
										
											2007-12-12 00:32:35 -05:00
										 |  |  |         " class." , | 
					
						
							|  |  |  |     ] { } make $description ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | M: word word-help* drop f ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-12 00:32:35 -05:00
										 |  |  | M: predicate word-help* drop \ $predicate ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : all-articles ( -- seq )
 | 
					
						
							|  |  |  |     articles get keys
 | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     all-words [ word-help ] filter append ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 02:39:45 -04:00
										 |  |  | : orphan-articles ( -- seq )
 | 
					
						
							|  |  |  |     articles get keys
 | 
					
						
							|  |  |  |     [ article-parent not ] filter ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : xref-help ( -- )
 | 
					
						
							|  |  |  |     all-articles [ xref-article ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : error? ( word -- ? )
 | 
					
						
							|  |  |  |     \ $error-description swap word-help elements empty? not ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : sort-articles ( seq -- newseq )
 | 
					
						
							| 
									
										
										
										
											2008-04-19 23:56:28 -04:00
										 |  |  |     [ dup article-title ] { } map>assoc sort-values keys ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : all-errors ( -- seq )
 | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     all-words [ error? ] filter sort-articles ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  | M: word article-name name>> ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: word article-title | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  |     dup [ parsing-word? ] [ symbol? ] bi or [ | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  |         name>>  | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] [ | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  |         [ name>> ] | 
					
						
							| 
									
										
										
										
											2008-06-08 17:47:20 -04:00
										 |  |  |         [ stack-effect [ effect>string " " prepend ] [ "" ] if* ] bi
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  |         append
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-22 04:37:46 -05:00
										 |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (word-help) ( word -- element )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2008-11-22 04:37:46 -05:00
										 |  |  |         { | 
					
						
							|  |  |  |             [ \ $vocabulary swap 2array , ] | 
					
						
							|  |  |  |             [ word-help % ] | 
					
						
							|  |  |  |             [ \ $related swap 2array , ] | 
					
						
							|  |  |  |             [ get-global [ \ $value swap 2array , ] when* ] | 
					
						
							|  |  |  |             [ \ $definition swap 2array , ] | 
					
						
							|  |  |  |         } cleave
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] { } make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-22 04:37:46 -05:00
										 |  |  | M: word article-content (word-help) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : word-with-methods ( word -- elements )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ (word-help) % ] | 
					
						
							|  |  |  |         [ \ $methods swap 2array , ] | 
					
						
							|  |  |  |         bi
 | 
					
						
							|  |  |  |     ] { } make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: generic article-content word-with-methods ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: class article-content word-with-methods ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | M: word article-parent "help-parent" word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: word set-article-parent swap "help-parent" set-word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $doc-path ( article -- )
 | 
					
						
							| 
									
										
										
										
											2008-09-06 20:13:59 -04:00
										 |  |  |     help-path [ | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             help-path-style get [ | 
					
						
							|  |  |  |                 "Parent topics: " write $links | 
					
						
							|  |  |  |             ] with-style | 
					
						
							|  |  |  |         ] ($block) | 
					
						
							| 
									
										
										
										
											2008-09-06 20:13:59 -04:00
										 |  |  |     ] unless-empty ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $title ( topic -- )
 | 
					
						
							|  |  |  |     title-style get [ | 
					
						
							|  |  |  |         title-style get [ | 
					
						
							|  |  |  |             dup [ | 
					
						
							|  |  |  |                 dup article-title swap >link write-object | 
					
						
							|  |  |  |             ] ($block) $doc-path | 
					
						
							|  |  |  |         ] with-nesting | 
					
						
							|  |  |  |     ] with-style nl ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-20 21:34:49 -05:00
										 |  |  | : print-topic ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2008-12-18 22:17:33 -05:00
										 |  |  |     >link | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     last-element off dup $title | 
					
						
							|  |  |  |     article-content print-content nl ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-20 21:34:49 -05:00
										 |  |  | SYMBOL: help-hook | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | help-hook global [ [ print-topic ] or ] change-at
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : help ( topic -- )
 | 
					
						
							|  |  |  |     help-hook get call ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : about ( vocab -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-08 02:08:52 -05:00
										 |  |  |     dup require | 
					
						
							| 
									
										
										
										
											2008-02-05 19:50:24 -05:00
										 |  |  |     dup vocab [ ] [ | 
					
						
							| 
									
										
										
										
											2008-03-19 20:15:32 -04:00
										 |  |  |         "No such vocabulary: " prepend throw
 | 
					
						
							| 
									
										
										
										
											2008-02-05 19:50:24 -05:00
										 |  |  |     ] ?if
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     dup vocab-help [ | 
					
						
							|  |  |  |         help | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         "The " write vocab-name write
 | 
					
						
							|  |  |  |         " vocabulary does not define a main help article." print
 | 
					
						
							|  |  |  |         "To define one, refer to \\ ABOUT: help" print
 | 
					
						
							|  |  |  |     ] ?if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ($index) ( articles -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 20:51:58 -04:00
										 |  |  |     sort-articles [ \ $subsection swap 2array ] map print-element ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $index ( element -- )
 | 
					
						
							| 
									
										
										
										
											2008-09-06 20:13:59 -04:00
										 |  |  |     first call [ ($index) ] unless-empty ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $about ( element -- )
 | 
					
						
							|  |  |  |     first vocab-help [ 1array $subsection ] when* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : :help-debugger ( -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-27 20:24:50 -05:00
										 |  |  |     nl
 | 
					
						
							|  |  |  |     "Debugger commands:" print
 | 
					
						
							|  |  |  |     nl
 | 
					
						
							| 
									
										
										
										
											2008-02-29 20:10:30 -05:00
										 |  |  |     ":s    - data stack at error time" print
 | 
					
						
							|  |  |  |     ":r    - retain stack at error time" print
 | 
					
						
							|  |  |  |     ":c    - call stack at error time" print
 | 
					
						
							| 
									
										
										
										
											2008-02-27 20:24:50 -05:00
										 |  |  |     ":edit - jump to source location (parse errors only)" print
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-29 20:10:30 -05:00
										 |  |  |     ":get  ( var -- value ) accesses variables at time of the error" print
 | 
					
						
							| 
									
										
										
										
											2008-03-16 04:43:30 -04:00
										 |  |  |     ":vars - list all variables at error time" print ;
 | 
					
						
							| 
									
										
										
										
											2008-02-27 20:24:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 13:29:24 -05:00
										 |  |  | : (:help) ( error -- )
 | 
					
						
							|  |  |  |     error-help [ help ] [ "No help for this error. " print ] if*
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  |     :help-debugger ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 13:29:24 -05:00
										 |  |  | : :help ( -- )
 | 
					
						
							|  |  |  |     error get (:help) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : remove-article ( name -- )
 | 
					
						
							|  |  |  |     dup articles get key? [ | 
					
						
							|  |  |  |         dup unxref-article | 
					
						
							|  |  |  |         dup articles get delete-at
 | 
					
						
							|  |  |  |     ] when drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : add-article ( article name -- )
 | 
					
						
							|  |  |  |     [ remove-article ] keep
 | 
					
						
							|  |  |  |     [ articles get set-at ] keep
 | 
					
						
							|  |  |  |     xref-article ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : remove-word-help ( word -- )
 | 
					
						
							|  |  |  |     dup word-help [ dup unxref-article ] when
 | 
					
						
							|  |  |  |     f "help" set-word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : set-word-help ( content word -- )
 | 
					
						
							|  |  |  |     [ remove-word-help ] keep
 | 
					
						
							|  |  |  |     [ swap "help" set-word-prop ] keep
 | 
					
						
							|  |  |  |     xref-article ;
 |