| 
									
										
										
										
											2010-02-09 04:21:05 -05:00
										 |  |  | ! Copyright (C) 2005, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2016-04-04 18:31:53 -04:00
										 |  |  | USING: accessors arrays assocs classes classes.error | 
					
						
							|  |  |  | classes.tuple combinators combinators.short-circuit | 
					
						
							|  |  |  | continuations debugger effects generic help.crossref help.markup | 
					
						
							|  |  |  | help.stylesheet help.topics io io.styles kernel locals make | 
					
						
							|  |  |  | namespaces prettyprint sequences sets sorting vocabs words | 
					
						
							|  |  |  | words.symbol ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: help | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: word-help* ( word -- content )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : word-help ( word -- content )
 | 
					
						
							| 
									
										
										
										
											2016-04-04 18:40:26 -04:00
										 |  |  |     dup "help" word-prop [ ] [ | 
					
						
							|  |  |  |         dup word-help* dup
 | 
					
						
							|  |  |  |        [ swap 2array 1array ] [ 2drop f ] if
 | 
					
						
							|  |  |  |     ] ?if ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-12 00:32:35 -05:00
										 |  |  | : $predicate ( element -- )
 | 
					
						
							| 
									
										
										
										
											2014-05-23 23:20:15 -04:00
										 |  |  |     { { "object" object } { "?" boolean } } $values | 
					
						
							| 
									
										
										
										
											2007-12-12 00:32:35 -05:00
										 |  |  |     [ | 
					
						
							|  |  |  |         "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 ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 18:40:26 -04:00
										 |  |  | : $default ( element -- )
 | 
					
						
							|  |  |  |     first stack-effect [ in>> ] [ out>> ] bi [ | 
					
						
							| 
									
										
										
										
											2016-04-04 18:31:53 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             dup pair? [ | 
					
						
							|  |  |  |                 first2 dup effect? [ \ $quotation swap 2array ] when
 | 
					
						
							|  |  |  |             ] [ | 
					
						
							|  |  |  |                 object
 | 
					
						
							| 
									
										
										
										
											2016-04-07 10:25:53 -04:00
										 |  |  |             ] if [ effect>string ] dip
 | 
					
						
							| 
									
										
										
										
											2016-04-04 18:31:53 -04:00
										 |  |  |         ] { } map>assoc
 | 
					
						
							| 
									
										
										
										
											2016-04-04 18:40:26 -04:00
										 |  |  |     ] bi@ append members $values ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: word word-help* drop \ $default ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 18:31:53 -04:00
										 |  |  | M: class word-help* drop f ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 18:40:26 -04:00
										 |  |  | M: predicate word-help* drop \ $predicate ;
 | 
					
						
							| 
									
										
										
										
											2007-12-12 00:32:35 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							| 
									
										
										
										
											2015-05-12 21:50:34 -04:00
										 |  |  |     [ article-parent ] reject ;
 | 
					
						
							| 
									
										
										
										
											2008-07-03 02:39:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : xref-help ( -- )
 | 
					
						
							|  |  |  |     all-articles [ xref-article ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : error? ( word -- ? )
 | 
					
						
							| 
									
										
										
										
											2013-04-06 16:35:37 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |         [ error-class? ] | 
					
						
							|  |  |  |         [ \ $error-description swap word-help elements empty? not ] | 
					
						
							|  |  |  |     } 1|| ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-09 04:21:05 -05:00
										 |  |  | M: word valid-article? drop t ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 [ | 
					
						
							| 
									
										
										
										
											2015-06-29 19:43:15 -04:00
										 |  |  |         name>> | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] [ | 
					
						
							| 
									
										
										
										
											2009-04-24 01:20:33 -04:00
										 |  |  |         [ unparse ] | 
					
						
							| 
									
										
										
										
											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 , ] | 
					
						
							| 
									
										
										
										
											2015-08-13 20:46:40 -04:00
										 |  |  |             [ dup global at [ get-global \ $value swap 2array , ] [ drop ] if ] | 
					
						
							| 
									
										
										
										
											2008-11-22 04:37:46 -05:00
										 |  |  |             [ \ $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) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : 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 ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-20 18:32:38 -05:00
										 |  |  | : ($title) ( topic -- )
 | 
					
						
							|  |  |  |     [ [ article-title ] [ >link ] bi write-object ] ($block) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 09:48:20 -04:00
										 |  |  | : ($navigation-table) ( element -- )
 | 
					
						
							| 
									
										
										
										
											2012-07-19 14:24:45 -04:00
										 |  |  |     help-path-style get table-style [ $table ] with-variable ;
 | 
					
						
							| 
									
										
										
										
											2009-09-10 09:48:20 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-18 07:37:05 -04:00
										 |  |  | : ($navigation-path) ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2015-08-16 14:32:54 -04:00
										 |  |  |     help-path-style get [ | 
					
						
							|  |  |  |        help-path [ reverse $breadcrumbs ] unless-empty
 | 
					
						
							|  |  |  |     ] with-style ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ($navigation-link) ( content element label -- )
 | 
					
						
							|  |  |  |     [ prefix 1array ] dip prefix , ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ($navigation-links) ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2015-08-16 14:38:38 -04:00
										 |  |  |     help-path-style get [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             [ prev-article [ 1array \ $long-link "Prev:" ($navigation-link) ] when* ] | 
					
						
							|  |  |  |             [ next-article [ 1array \ $long-link "Next:" ($navigation-link) ] when* ] | 
					
						
							|  |  |  |             bi
 | 
					
						
							|  |  |  |         ] { } make [ ($navigation-table) ] unless-empty
 | 
					
						
							|  |  |  |     ] with-style ;
 | 
					
						
							| 
									
										
										
										
											2015-07-18 07:37:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : $title ( topic -- )
 | 
					
						
							|  |  |  |     title-style get [ | 
					
						
							| 
									
										
										
										
											2009-09-11 20:35:56 -04:00
										 |  |  |         title-style get [ | 
					
						
							| 
									
										
										
										
											2015-08-16 14:32:54 -04:00
										 |  |  |             [ ($title) ] | 
					
						
							|  |  |  |             [ ($navigation-path) ] | 
					
						
							|  |  |  |             [ ($navigation-links) ] tri
 | 
					
						
							| 
									
										
										
										
											2009-09-11 20:35:56 -04:00
										 |  |  |         ] with-nesting | 
					
						
							| 
									
										
										
										
											2009-10-04 07:17:54 -04:00
										 |  |  |     ] with-style ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-20 21:34:49 -05:00
										 |  |  | : print-topic ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2008-12-18 22:17:33 -05:00
										 |  |  |     >link | 
					
						
							| 
									
										
										
										
											2008-12-20 18:32:38 -05:00
										 |  |  |     last-element off
 | 
					
						
							| 
									
										
										
										
											2015-08-16 14:32:54 -04:00
										 |  |  |     [ $title ($blank-line) ] | 
					
						
							|  |  |  |     [ article-content print-content nl ] bi ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-20 21:34:49 -05:00
										 |  |  | SYMBOL: help-hook | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 15:18:35 -04:00
										 |  |  | help-hook [ [ print-topic ] ] initialize
 | 
					
						
							| 
									
										
										
										
											2008-11-20 21:34:49 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : help ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2009-02-09 02:47:31 -05:00
										 |  |  |     help-hook get call( topic -- ) ;
 | 
					
						
							| 
									
										
										
										
											2008-11-20 21:34:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : ($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 -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-17 03:19:50 -04:00
										 |  |  |     first call( -- seq ) [ ($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 -- )
 | 
					
						
							| 
									
										
										
										
											2009-04-22 05:20:38 -04:00
										 |  |  |     articles get delete-at ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : add-article ( article name -- )
 | 
					
						
							| 
									
										
										
										
											2016-03-20 17:39:13 -04:00
										 |  |  |     [ articles get set-at ] keep xref-article ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : remove-word-help ( word -- )
 | 
					
						
							|  |  |  |     f "help" set-word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : set-word-help ( content word -- )
 | 
					
						
							| 
									
										
										
										
											2016-03-20 17:39:13 -04:00
										 |  |  |     [ swap "help" set-word-prop ] keep xref-article ;
 |