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 ( -- str/obj/f )
12 ?scan-token dup search {
13 { [ dup \ } 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* ;
24 : push-help-space ( accum sbuf -- accum sbuf )
26 over empty? not pick ?last \ $nl eq? not and
28 dup last CHAR: \s eq? not
29 ] if [ CHAR: \s suffix! ] when ;
31 :: parse-help-text ( -- seq )
32 V{ } clone SBUF" " clone [
33 lexer get line>> parse-help-token [
34 lexer get line>> swap - 1 > [
40 dup ?first " .,;:" member? [
41 [ push-help-space ] dip
45 [ push-help-text ] bi*
49 ] loop [ >string suffix! ] unless-empty >array ; inline
51 : parse-help-values ( -- seq )
52 [ scan-token dup "}" = not ] [
54 drop \ } parse-until >array
56 ":" ?tail drop scan-object 2array
60 : example-lines ( seq -- seq' )
62 string-lines [ [ blank? ] trim ] map harvest
63 dup length 1 - over [ unescape-string ] change-nth
66 : make-example ( seq -- seq )
68 example-lines dup length 1 > [ \ $example prefix ] when
71 : parse-help-examples ( -- seq )
72 \ } parse-until [ make-example ] { } map-as ;
74 : parse-help-example ( -- seq )
75 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
76 [ first example-lines ] [ >array ] if ;
78 : help-text? ( word -- ? )
80 $description $snippet $emphasis $strong $url $heading
81 $subheading $syntax $class-description
82 $error-description $var-description $contract $notes
83 $curious $deprecated $errors $side-effects $content
87 : help-values? ( word -- ? )
88 { $values $inputs $outputs } member-eq? ;
90 : help-examples? ( word -- ? )
91 { $examples } member-eq? ;
93 : help-example? ( word -- ? )
94 { $example $unchecked-example $code } member-eq? ;
99 scan-object dup \ } eq? [ drop { } ] [
101 { [ dup help-text? ] [ parse-help-text ] }
102 { [ dup help-values? ] [ parse-help-values ] }
103 { [ dup help-example? ] [ parse-help-example ] }
104 { [ dup help-examples? ] [ parse-help-examples ] }
105 [ \ } parse-until >array ]
110 H{ { "{" POSTPONE: HELP{ } } [
111 scan-word bootstrap-word
112 [ >link save-location ]
113 [ [ parse-array-def ] dip set-word-help ]
117 ERROR: article-expects-name-and-title got ;
122 dup length 2 < [ article-expects-name-and-title ] when
123 [ first2 ] [ 2 tail ] bi <article>
124 over add-article >link
125 ] dip remember-definition ;
128 current-vocab scan-object >>help changed-definition ;