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 [ dup empty? not over ?last CHAR: \s eq? not and ]
27 [ over empty? not pick ?last \ $nl eq? not and ]
28 } 0|| [ CHAR: \s suffix! ] when ;
30 :: parse-help-text ( -- seq )
31 V{ } clone SBUF" " clone [
32 lexer get line>> parse-help-token [
33 lexer get line>> swap - 1 > [
39 dup ?first " .,;:" member? [
40 [ push-help-space ] dip
44 [ push-help-text ] bi*
48 ] loop [ >string suffix! ] unless-empty >array ; inline
50 : parse-help-values ( -- seq )
51 [ scan-token dup "}" = not ] [
53 drop \ } parse-until >array
55 ":" ?tail drop scan-object 2array
59 : example-lines ( seq -- seq' )
60 dup string? [ string-lines [ [ blank? ] trim ] map harvest ] when ;
62 : make-example ( seq -- seq )
64 example-lines dup length 1 > [ \ $example prefix ] when
67 : parse-help-examples ( -- seq )
68 \ } parse-until [ make-example ] { } map-as ;
70 : parse-help-example ( -- seq )
71 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
72 [ first example-lines ] [ >array ] if ;
74 : help-text? ( word -- ? )
76 $description $snippet $emphasis $strong $url $heading
77 $subheading $syntax $class-description
78 $error-description $var-description $contract $notes
79 $curious $deprecated $errors $side-effects $content
83 : help-values? ( word -- ? )
84 { $values $inputs $outputs } member-eq? ;
86 : help-examples? ( word -- ? )
87 { $examples } member-eq? ;
89 : help-example? ( word -- ? )
90 { $example $unchecked-example $code } member-eq? ;
95 scan-object dup \ } eq? [ drop { } ] [
97 { [ dup help-text? ] [ parse-help-text ] }
98 { [ dup help-values? ] [ parse-help-values ] }
99 { [ dup help-example? ] [ parse-help-example ] }
100 { [ dup help-examples? ] [ parse-help-examples ] }
101 [ \ } parse-until >array ]
106 H{ { "{" POSTPONE: HELP{ } } [
107 scan-word bootstrap-word
108 [ >link save-location ]
109 [ [ parse-array-def ] dip set-word-help ]
113 ERROR: article-expects-name-and-title got ;
118 dup length 2 < [ article-expects-name-and-title ] when
119 [ first2 ] [ 2 tail ] bi <article>
120 over add-article >link
121 ] dip remember-definition ;
124 current-vocab scan-object >>help changed-definition ;