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 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' )
61 dup string? [ string-lines [ [ blank? ] trim ] map harvest ] when ;
63 : make-example ( seq -- seq )
65 example-lines dup length 1 > [ \ $example prefix ] when
68 : parse-help-examples ( -- seq )
69 \ } parse-until [ make-example ] { } map-as ;
71 : parse-help-example ( -- seq )
72 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
73 [ first example-lines ] [ >array ] if ;
75 : help-text? ( word -- ? )
77 $description $snippet $emphasis $strong $url $heading
78 $subheading $syntax $class-description
79 $error-description $var-description $contract $notes
80 $curious $deprecated $errors $side-effects $content
84 : help-values? ( word -- ? )
85 { $values $inputs $outputs } member-eq? ;
87 : help-examples? ( word -- ? )
88 { $examples } member-eq? ;
90 : help-example? ( word -- ? )
91 { $example $unchecked-example $code } member-eq? ;
96 scan-object dup \ } eq? [ drop { } ] [
98 { [ dup help-text? ] [ parse-help-text ] }
99 { [ dup help-values? ] [ parse-help-values ] }
100 { [ dup help-example? ] [ parse-help-example ] }
101 { [ dup help-examples? ] [ parse-help-examples ] }
102 [ \ } parse-until >array ]
107 H{ { "{" POSTPONE: HELP{ } } [
108 scan-word bootstrap-word
109 [ >link save-location ]
110 [ [ parse-array-def ] dip set-word-help ]
114 ERROR: article-expects-name-and-title got ;
119 dup length 2 < [ article-expects-name-and-title ] when
120 [ first2 ] [ 2 tail ] bi <article>
121 over add-article >link
122 ] dip remember-definition ;
125 current-vocab scan-object >>help changed-definition ;