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 )
13 [ "syntax" lookup-word ]
14 [ "help.markup" lookup-word ]
15 [ dup ?last ":{[(" member-eq? [ search ] [ drop f ] if ]
17 { [ dup not ] [ drop ] }
18 { [ dup end eq? ] [ 2drop f ] }
19 { [ dup parsing-word? ] [
20 nip V{ } clone swap execute-parsing first
21 dup wrapper? [ wrapped>> \ $link swap 2array ] when ] }
25 : push-help-text ( accum sbuf obj -- accum sbuf' )
26 [ dup empty? [ >string suffix! SBUF" " clone ] unless ]
27 [ [ suffix! ] curry dip ] bi* ;
31 : push-help-space ( accum sbuf -- accum sbuf )
34 pick ?last dup array? [ ?first ] when
37 dup last CHAR: \s eq? not
38 ] if [ CHAR: \s suffix! ] when ;
40 :: parse-help-text ( end -- seq )
41 V{ } clone SBUF" " clone [
43 end parse-help-token :> obj
46 obj string? n m - 1 > and [
47 { [ dup empty? not ] [ over ?last string? ] } 0||
48 [ \ $nl push-help-text ] when
54 dup ?first " .,;:" member? [
55 [ push-help-space ] dip
59 [ push-help-text ] bi*
63 ] loop [ >string suffix! ] unless-empty >array ; inline
65 : parse-help-values ( -- seq )
66 [ scan-token dup "}" = not ] [
68 drop \ } parse-until >array
70 ":" ?tail drop scan-object 2array
74 : code-lines ( str -- seq )
75 string-lines [ [ blank? ] trim ] map harvest ;
77 : make-example ( seq -- seq )
80 dup { [ array? ] [ length 1 > ] } 1&& [
81 dup length 1 - over [ unescape-string ] change-nth
86 : parse-help-examples ( -- seq )
87 \ } parse-until [ make-example ] { } map-as ;
89 : parse-help-code ( -- seq )
90 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
91 [ first code-lines ] [ >array ] if ;
93 : help-text? ( word -- ? )
95 $description $snippet $emphasis $strong $url $heading
96 $subheading $syntax $class-description
97 $error-description $var-description $contract $notes
98 $curious $deprecated $errors $side-effects $content
102 : help-code? ( word -- ? )
103 { $example $unchecked-example $code } member-eq? ;
105 : help-block? ( word -- ? )
107 $description $heading $subheading $syntax
108 $class-description $error-description $var-description
109 $contract $notes $curious $deprecated $errors
110 $side-effects $content $warning $subsections $nl
113 : help-values? ( word -- ? )
114 { $values $inputs $outputs } member-eq? ;
116 : help-examples? ( word -- ? )
117 { $examples } member-eq? ;
122 scan-object dup \ } eq? [ drop { } ] [
124 { [ dup help-text? ] [ \ } parse-help-text ] }
125 { [ dup help-code? ] [ parse-help-code ] }
126 { [ dup help-values? ] [ parse-help-values ] }
127 { [ dup help-examples? ] [ parse-help-examples ] }
128 [ \ } parse-until >array ]
133 H{ { "{" POSTPONE: HELP{ } } [
134 scan-word bootstrap-word
135 [ >link save-location ]
136 [ [ parse-array-def ] dip set-word-help ]
142 scan-object scan-object
143 \ ; parse-help-text <article>
144 over add-article >link
145 ] dip remember-definition ;
148 current-vocab scan-object >>help changed-definition ;