| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! Copyright (C) 2006, 2007 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: sequences parser kernel help help.markup help.topics | 
					
						
							| 
									
										
										
										
											2008-03-12 20:55:06 -04:00
										 |  |  | words strings classes tools.vocabs namespaces io | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | io.streams.string prettyprint definitions arrays vectors | 
					
						
							|  |  |  | combinators splitting debugger hashtables sorting effects vocabs | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | vocabs.loader assocs editors continuations classes.predicate | 
					
						
							| 
									
										
										
										
											2008-04-14 03:40:32 -04:00
										 |  |  | macros combinators.lib sequences.lib math sets ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: help.lint | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-example ( element -- )
 | 
					
						
							| 
									
										
										
										
											2008-04-26 03:01:43 -04:00
										 |  |  |     rest [ | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |         1 head* "\n" join 1vector
 | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             use [ clone ] change
 | 
					
						
							|  |  |  |             [ eval>string ] with-datastack
 | 
					
						
							|  |  |  |         ] with-scope peek "\n" ?tail drop
 | 
					
						
							|  |  |  |     ] keep
 | 
					
						
							|  |  |  |     peek assert= ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-examples ( word element -- )
 | 
					
						
							|  |  |  |     nip \ $example swap elements [ check-example ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : extract-values ( element -- seq )
 | 
					
						
							|  |  |  |     \ $values swap elements dup empty? [ | 
					
						
							| 
									
										
										
										
											2008-04-26 03:01:43 -04:00
										 |  |  |         first rest [ first ] map prune natural-sort | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] unless ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : effect-values ( word -- seq )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 22:01:39 -04:00
										 |  |  |     stack-effect dup effect-in swap effect-out append [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             { [ dup word? ] [ word-name ] } | 
					
						
							|  |  |  |             { [ dup integer? ] [ drop "object" ] } | 
					
						
							|  |  |  |             { [ dup string? ] [ ] } | 
					
						
							|  |  |  |         } cond
 | 
					
						
							|  |  |  |     ] map prune natural-sort ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | : contains-funky-elements? ( element -- ? )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |         $shuffle | 
					
						
							|  |  |  |         $values-x/y | 
					
						
							|  |  |  |         $predicate | 
					
						
							|  |  |  |         $class-description | 
					
						
							|  |  |  |         $error-description | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  |     } swap [ elements f like ] curry contains? ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-values ( word element -- )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         [ over "declared-effect" word-prop ] | 
					
						
							|  |  |  |         [ dup contains-funky-elements? not ] | 
					
						
							|  |  |  |         [ over macro? not ] | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             2dup extract-values >array
 | 
					
						
							|  |  |  |             >r effect-values >array
 | 
					
						
							|  |  |  |             r> assert=
 | 
					
						
							|  |  |  |             t
 | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     } && 3drop ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : check-see-also ( word element -- )
 | 
					
						
							|  |  |  |     nip \ $see-also swap elements [ | 
					
						
							| 
									
										
										
										
											2008-04-26 03:01:43 -04:00
										 |  |  |         rest dup prune [ length ] bi@ assert=
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : vocab-exists? ( name -- ? )
 | 
					
						
							|  |  |  |     dup vocab swap "all-vocabs" get member? or ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-modules ( word element -- )
 | 
					
						
							|  |  |  |     nip \ $vocab-link swap elements [ | 
					
						
							|  |  |  |         second
 | 
					
						
							|  |  |  |         vocab-exists? [ "Missing vocabulary" throw ] unless
 | 
					
						
							|  |  |  |     ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-rendering ( word element -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-15 23:20:31 -05:00
										 |  |  |     [ help ] with-string-writer drop ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | : all-word-help ( words -- seq )
 | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     [ word-help ] filter ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: help-error topic ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <help-error> ( topic delegate -- error )
 | 
					
						
							|  |  |  |     { set-help-error-topic set-delegate } help-error construct ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | M: help-error error. | 
					
						
							|  |  |  |     "In " write dup help-error-topic ($link) nl
 | 
					
						
							|  |  |  |     delegate error. ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-something ( obj quot -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  |     flush [ <help-error> , ] recover ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : check-word ( word -- )
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  |     dup word-help [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             dup word-help [ | 
					
						
							|  |  |  |                 2dup check-examples | 
					
						
							|  |  |  |                 2dup check-values | 
					
						
							|  |  |  |                 2dup check-see-also | 
					
						
							|  |  |  |                 2dup check-modules | 
					
						
							|  |  |  |                 2dup drop check-rendering | 
					
						
							|  |  |  |             ] assert-depth 2drop
 | 
					
						
							|  |  |  |         ] check-something | 
					
						
							|  |  |  |     ] [ drop ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-words ( words -- ) [ check-word ] each ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : check-article ( article -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ dup check-rendering ] assert-depth drop
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  |     ] check-something ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  | : group-articles ( -- assoc )
 | 
					
						
							|  |  |  |     articles get keys
 | 
					
						
							|  |  |  |     vocabs [ dup vocab-docs-path swap ] H{ } map>assoc
 | 
					
						
							|  |  |  |     H{ } clone [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             >r >r dup >link where ?first r> at r> [ ?push ] change-at
 | 
					
						
							|  |  |  |         ] 2curry each
 | 
					
						
							|  |  |  |     ] keep ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-vocab ( vocab -- seq )
 | 
					
						
							|  |  |  |     "Checking " write dup write "..." print
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         dup words [ check-word ] each
 | 
					
						
							|  |  |  |         "vocab-articles" get at [ check-article ] each
 | 
					
						
							|  |  |  |     ] { } make ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  | : run-help-lint ( prefix -- alist )
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  |     [ | 
					
						
							|  |  |  |         all-vocabs-seq [ vocab-name ] map "all-vocabs" set
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  |         articles get keys "group-articles" set
 | 
					
						
							|  |  |  |         child-vocabs | 
					
						
							|  |  |  |         [ dup check-vocab ] { } map>assoc
 | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |         [ nip empty? not ] assoc-filter
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  |     ] with-scope ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : typos. ( assoc -- )
 | 
					
						
							|  |  |  |     dup empty? [ | 
					
						
							|  |  |  |         drop
 | 
					
						
							|  |  |  |         "==== ALL CHECKS PASSED" print
 | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             swap vocab-heading. | 
					
						
							|  |  |  |             [ error. nl ] each
 | 
					
						
							|  |  |  |         ] assoc-each
 | 
					
						
							|  |  |  |     ] if ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  | : help-lint ( prefix -- ) run-help-lint typos. ;
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  | : help-lint-all ( -- ) "" help-lint ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-11 22:36:40 -05:00
										 |  |  | : unlinked-words ( words -- seq )
 | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     all-word-help [ article-parent not ] filter ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : linked-undocumented-words ( -- seq )
 | 
					
						
							|  |  |  |     all-words | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     [ word-help not ] filter
 | 
					
						
							|  |  |  |     [ article-parent ] filter
 | 
					
						
							|  |  |  |     [ "predicating" word-prop not ] filter ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-26 21:20:30 -05:00
										 |  |  | MAIN: help-lint |