1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays ascii combinators
4 combinators.short-circuit compiler.units definitions help
5 help.markup help.topics kernel lexer math namespaces parser
6 sequences splitting strings strings.parser vocabs.parser words ;
11 :: parse-help-token ( end -- str/obj/f )
12 ?scan-token dup search {
13 { [ dup end eq? ] [ 2drop f ] }
14 { [ dup parsing-word? ] [
15 nip V{ } clone swap execute-parsing first
16 dup wrapper? [ wrapped>> \ $link swap 2array ] when ] }
17 { [ dup [ vocabulary>> "help.markup" = ] when ] [ nip ] }
21 : push-help-text ( accum sbuf obj -- accum sbuf' )
22 [ dup empty? [ >string suffix! SBUF" " clone ] unless ]
23 [ [ suffix! ] curry dip ] bi* ;
27 : push-help-space ( accum sbuf -- accum sbuf )
30 pick ?last dup array? [ ?first ] when
33 dup last CHAR: \s eq? not
34 ] if [ CHAR: \s suffix! ] when ;
36 :: parse-help-text ( end -- seq )
37 V{ } clone SBUF" " clone [
39 end parse-help-token :> obj
42 obj string? n m - 1 > and [
43 { [ dup empty? not ] [ over ?last string? ] } 0||
44 [ \ $nl push-help-text ] when
50 dup ?first " .,;:" member? [
51 [ push-help-space ] dip
55 [ push-help-text ] bi*
59 ] loop [ >string suffix! ] unless-empty >array ; inline
61 : parse-help-values ( -- seq )
62 [ scan-token dup "}" = not ] [
64 drop \ } parse-until >array
66 ":" ?tail drop scan-object 2array
70 : code-lines ( str -- seq )
71 string-lines [ [ blank? ] trim ] map harvest ;
73 : make-example ( seq -- seq )
76 dup { [ array? ] [ length 1 > ] } 1&& [
77 dup length 1 - over [ unescape-string ] change-nth
82 : parse-help-examples ( -- seq )
83 \ } parse-until [ make-example ] { } map-as ;
85 : parse-help-code ( -- seq )
86 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
87 [ first code-lines ] [ >array ] if ;
89 : help-text? ( word -- ? )
91 $description $snippet $emphasis $strong $url $heading
92 $subheading $syntax $class-description
93 $error-description $var-description $contract $notes
94 $curious $deprecated $errors $side-effects $content
98 : help-code? ( word -- ? )
99 { $example $unchecked-example $code } member-eq? ;
101 : help-block? ( word -- ? )
103 $description $heading $subheading $syntax
104 $class-description $error-description $var-description
105 $contract $notes $curious $deprecated $errors
106 $side-effects $content $warning $subsections $nl
109 : help-values? ( word -- ? )
110 { $values $inputs $outputs } member-eq? ;
112 : help-examples? ( word -- ? )
113 { $examples } member-eq? ;
118 scan-object dup \ } eq? [ drop { } ] [
120 { [ dup help-text? ] [ \ } parse-help-text ] }
121 { [ dup help-code? ] [ parse-help-code ] }
122 { [ dup help-values? ] [ parse-help-values ] }
123 { [ dup help-examples? ] [ parse-help-examples ] }
124 [ \ } parse-until >array ]
129 H{ { "{" POSTPONE: HELP{ } } [
130 scan-word bootstrap-word
131 [ >link save-location ]
132 [ [ parse-array-def ] dip set-word-help ]
138 scan-object scan-object
139 \ ; parse-help-text <article>
140 over add-article >link
141 ] dip remember-definition ;
144 current-vocab scan-object >>help changed-definition ;