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 not ] [ drop ] }
14 { [ dup end eq? ] [ 2drop f ] }
15 { [ dup parsing-word? ] [
16 nip V{ } clone swap execute-parsing first
17 dup wrapper? [ wrapped>> \ $link swap 2array ] when ] }
18 { [ dup vocabulary>> "help.markup" = ] [ nip ] }
22 : push-help-text ( accum sbuf obj -- accum sbuf' )
23 [ dup empty? [ >string suffix! SBUF" " clone ] unless ]
24 [ [ suffix! ] curry dip ] bi* ;
28 : push-help-space ( accum sbuf -- accum sbuf )
31 pick ?last dup array? [ ?first ] when
34 dup last CHAR: \s eq? not
35 ] if [ CHAR: \s suffix! ] when ;
37 :: parse-help-text ( end -- seq )
38 V{ } clone SBUF" " clone [
40 end parse-help-token :> obj
43 obj string? n m - 1 > and [
44 { [ dup empty? not ] [ over ?last string? ] } 0||
45 [ \ $nl push-help-text ] when
51 dup ?first " .,;:" member? [
52 [ push-help-space ] dip
56 [ push-help-text ] bi*
60 ] loop [ >string suffix! ] unless-empty >array ; inline
62 : parse-help-values ( -- seq )
63 [ scan-token dup "}" = not ] [
65 drop \ } parse-until >array
67 ":" ?tail drop scan-object 2array
71 : code-lines ( str -- seq )
72 string-lines [ [ blank? ] trim ] map harvest ;
74 : make-example ( seq -- seq )
77 dup { [ array? ] [ length 1 > ] } 1&& [
78 dup length 1 - over [ unescape-string ] change-nth
83 : parse-help-examples ( -- seq )
84 \ } parse-until [ make-example ] { } map-as ;
86 : parse-help-code ( -- seq )
87 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
88 [ first code-lines ] [ >array ] if ;
90 : help-text? ( word -- ? )
92 $description $snippet $emphasis $strong $url $heading
93 $subheading $syntax $class-description
94 $error-description $var-description $contract $notes
95 $curious $deprecated $errors $side-effects $content
99 : help-code? ( word -- ? )
100 { $example $unchecked-example $code } member-eq? ;
102 : help-block? ( word -- ? )
104 $description $heading $subheading $syntax
105 $class-description $error-description $var-description
106 $contract $notes $curious $deprecated $errors
107 $side-effects $content $warning $subsections $nl
110 : help-values? ( word -- ? )
111 { $values $inputs $outputs } member-eq? ;
113 : help-examples? ( word -- ? )
114 { $examples } member-eq? ;
119 scan-object dup \ } eq? [ drop { } ] [
121 { [ dup help-text? ] [ \ } parse-help-text ] }
122 { [ dup help-code? ] [ parse-help-code ] }
123 { [ dup help-values? ] [ parse-help-values ] }
124 { [ dup help-examples? ] [ parse-help-examples ] }
125 [ \ } parse-until >array ]
130 H{ { "{" POSTPONE: HELP{ } } [
131 scan-word bootstrap-word
132 [ >link save-location ]
133 [ [ parse-array-def ] dip set-word-help ]
139 scan-object scan-object
140 \ ; parse-help-text <article>
141 over add-article >link
142 ] dip remember-definition ;
145 current-vocab scan-object >>help changed-definition ;