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 [ dup "syntax" lookup-word ]
14 [ dup "help.markup" lookup-word ]
16 { [ dup not ] [ drop ] }
17 { [ dup end eq? ] [ 2drop f ] }
18 { [ dup parsing-word? ] [
19 nip V{ } clone swap execute-parsing first
20 dup wrapper? [ wrapped>> \ $link swap 2array ] when ] }
24 : push-help-text ( accum sbuf obj -- accum sbuf' )
25 [ dup empty? [ >string suffix! SBUF" " clone ] unless ]
26 [ [ suffix! ] curry dip ] bi* ;
30 : push-help-space ( accum sbuf -- accum sbuf )
33 pick ?last dup array? [ ?first ] when
36 dup last CHAR: \s eq? not
37 ] if [ CHAR: \s suffix! ] when ;
39 :: parse-help-text ( end -- seq )
40 V{ } clone SBUF" " clone [
42 end parse-help-token :> obj
45 obj string? n m - 1 > and [
46 { [ dup empty? not ] [ over ?last string? ] } 0||
47 [ \ $nl push-help-text ] when
53 dup ?first " .,;:" member? [
54 [ push-help-space ] dip
58 [ push-help-text ] bi*
62 ] loop [ >string suffix! ] unless-empty >array ; inline
64 : parse-help-values ( -- seq )
65 [ scan-token dup "}" = not ] [
67 drop \ } parse-until >array
69 ":" ?tail drop scan-object 2array
73 : code-lines ( str -- seq )
74 string-lines [ [ blank? ] trim ] map harvest ;
76 : make-example ( seq -- seq )
79 dup { [ array? ] [ length 1 > ] } 1&& [
80 dup length 1 - over [ unescape-string ] change-nth
85 : parse-help-examples ( -- seq )
86 \ } parse-until [ make-example ] { } map-as ;
88 : parse-help-code ( -- seq )
89 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
90 [ first code-lines ] [ >array ] if ;
92 : help-text? ( word -- ? )
94 $description $snippet $emphasis $strong $url $heading
95 $subheading $syntax $class-description
96 $error-description $var-description $contract $notes
97 $curious $deprecated $errors $side-effects $content
101 : help-code? ( word -- ? )
102 { $example $unchecked-example $code } member-eq? ;
104 : help-block? ( word -- ? )
106 $description $heading $subheading $syntax
107 $class-description $error-description $var-description
108 $contract $notes $curious $deprecated $errors
109 $side-effects $content $warning $subsections $nl
112 : help-values? ( word -- ? )
113 { $values $inputs $outputs } member-eq? ;
115 : help-examples? ( word -- ? )
116 { $examples } member-eq? ;
121 scan-object dup \ } eq? [ drop { } ] [
123 { [ dup help-text? ] [ \ } parse-help-text ] }
124 { [ dup help-code? ] [ parse-help-code ] }
125 { [ dup help-values? ] [ parse-help-values ] }
126 { [ dup help-examples? ] [ parse-help-examples ] }
127 [ \ } parse-until >array ]
132 H{ { "{" POSTPONE: HELP{ } } [
133 scan-word bootstrap-word
134 [ >link save-location ]
135 [ [ parse-array-def ] dip set-word-help ]
141 scan-object scan-object
142 \ ; parse-help-text <article>
143 over add-article >link
144 ] dip remember-definition ;
147 current-vocab scan-object >>help changed-definition ;