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 ;
13 :: parse-help-token ( end -- str/obj/f )
15 [ "{" = [ \ HELP{ ] [ f ] if ]
16 [ "syntax" lookup-word ]
17 [ "help.markup" lookup-word ]
18 [ dup ?last ":{[(/\"" member-eq? [ search ] [ drop f ] if ]
20 { [ dup not ] [ drop ] }
21 { [ dup end eq? ] [ 2drop f ] }
22 { [ dup parsing-word? ] [
23 nip V{ } clone swap execute-parsing first
24 dup wrapper? [ wrapped>> \ $link swap 2array ] when ] }
28 : push-help-text ( accum sbuf obj -- accum sbuf' )
29 [ dup empty? [ >string suffix! SBUF" " clone ] unless ]
30 [ [ suffix! ] curry dip ] bi* ;
32 : help-block? ( word -- ? )
34 $description $heading $subheading $syntax
35 $class-description $error-description $var-description
36 $contract $notes $curious $deprecated $errors
37 $side-effects $content $warning $subsections $nl
38 $list $table $example $unchecked-example $code
41 : push-help-space ( accum sbuf -- accum sbuf )
44 pick ?last dup array? [ ?first ] when
47 dup last CHAR: \s eq? not
48 ] if [ CHAR: \s suffix! ] when ;
50 :: parse-help-text ( end -- seq )
51 V{ } clone SBUF" " clone [
53 end parse-help-token :> obj
56 obj string? n m - 1 > and [
57 { [ dup empty? not ] [ over ?last string? ] } 0||
58 [ \ $nl push-help-text ] when
64 dup ?first " .,;:" member? [
65 [ push-help-space ] dip
69 [ push-help-text ] bi*
73 ] loop [ >string suffix! ] unless-empty >array ; inline
75 : parse-help-values ( -- seq )
76 [ scan-token dup "}" = not ] [
78 drop \ } parse-until >array
80 ":" ?tail drop scan-object 2array
84 : make-example ( str -- seq )
85 split-lines dup { [ array? ] [ length 1 > ] } 1&& [
86 dup length 1 - over [ unescape-string ] change-nth
90 : parse-help-examples ( -- seq )
91 \ } parse-until dup [ string? ] all?
92 [ [ make-example ] { } map-as ] [ >array ] if ;
94 : parse-help-code ( -- seq )
95 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
96 [ first split-lines ] [ >array ] if ;
98 : help-text? ( word -- ? )
100 $description $snippet $emphasis $strong $url $heading
101 $subheading $syntax $class-description
102 $error-description $var-description $contract $notes
103 $curious $deprecated $errors $side-effects $content
104 $slot $image $warning
107 : help-code? ( word -- ? )
108 { $example $unchecked-example $code } member-eq? ;
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 ;