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 ] }
20 : push-help-text ( accum sbuf obj -- accum sbuf' )
21 [ dup empty? [ >string suffix! SBUF" " clone ] unless ]
22 [ [ suffix! ] curry dip ] bi* ;
26 : push-help-space ( accum sbuf -- accum sbuf )
29 pick ?last dup array? [ ?first ] when
32 dup last CHAR: \s eq? not
33 ] if [ CHAR: \s suffix! ] when ;
35 :: parse-help-text ( end -- seq )
36 V{ } clone SBUF" " clone [
38 end parse-help-token :> obj
41 obj string? n m - 1 > and [
42 { [ dup empty? not ] [ over ?last string? ] } 0||
43 [ \ $nl push-help-text ] when
49 dup ?first " .,;:" member? [
50 [ push-help-space ] dip
54 [ push-help-text ] bi*
58 ] loop [ >string suffix! ] unless-empty >array ; inline
60 : parse-help-values ( -- seq )
61 [ scan-token dup "}" = not ] [
63 drop \ } parse-until >array
65 ":" ?tail drop scan-object 2array
69 : code-lines ( seq -- seq' )
70 dup { [ string? ] [ [ blank? not ] member? ] } 1&& [
71 string-lines [ [ blank? ] trim ] map harvest
72 dup length 1 = [ first ] when
75 : make-example ( seq -- seq )
78 dup { [ array? ] [ length 1 > ] } 1&& [
79 dup length 1 - over [ unescape-string ] change-nth
84 : parse-help-examples ( -- seq )
85 \ } parse-until [ make-example ] { } map-as ;
87 : parse-help-code ( -- seq )
88 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
89 [ first code-lines ] [ >array ] if ;
91 : help-text? ( word -- ? )
93 $description $snippet $emphasis $strong $url $heading
94 $subheading $syntax $class-description
95 $error-description $var-description $contract $notes
96 $curious $deprecated $errors $side-effects $content
100 : help-code? ( word -- ? )
101 { $example $unchecked-example $code } member-eq? ;
103 : help-block? ( word -- ? )
105 $description $heading $subheading $syntax
106 $class-description $error-description $var-description
107 $contract $notes $curious $deprecated $errors
108 $side-effects $content $warning $subsections $nl
111 : help-values? ( word -- ? )
112 { $values $inputs $outputs } member-eq? ;
114 : help-examples? ( word -- ? )
115 { $examples } member-eq? ;
120 scan-object dup \ } eq? [ drop { } ] [
122 { [ dup help-text? ] [ \ } parse-help-text ] }
123 { [ dup help-code? ] [ parse-help-code ] }
124 { [ dup help-values? ] [ parse-help-values ] }
125 { [ dup help-examples? ] [ parse-help-examples ] }
126 [ \ } parse-until >array ]
131 H{ { "{" POSTPONE: HELP{ } } [
132 scan-word bootstrap-word
133 [ >link save-location ]
134 [ [ parse-array-def ] dip set-word-help ]
140 scan-object scan-object
141 \ ; parse-help-text <article>
142 over add-article >link
143 ] dip remember-definition ;
146 current-vocab scan-object >>help changed-definition ;