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 )
12 ?scan-token dup search {
13 { [ dup end 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 ( end -- seq )
32 V{ } clone SBUF" " clone [
34 end parse-help-token :> obj
37 obj string? n m - 1 > and [
38 { [ dup empty? not ] [ over ?last string? ] } 0||
39 [ \ $nl push-help-text ] when
45 dup ?first " .,;:" member? [
46 [ push-help-space ] dip
50 [ push-help-text ] bi*
54 ] loop [ >string suffix! ] unless-empty >array ; inline
56 : parse-help-values ( -- seq )
57 [ scan-token dup "}" = not ] [
59 drop \ } parse-until >array
61 ":" ?tail drop scan-object 2array
65 : example-lines ( seq -- seq' )
67 string-lines [ [ blank? ] trim ] map harvest
68 dup length 1 - over [ unescape-string ] change-nth
71 : make-example ( seq -- seq )
73 example-lines dup length 1 > [ \ $example prefix ] when
76 : parse-help-examples ( -- seq )
77 \ } parse-until [ make-example ] { } map-as ;
79 : parse-help-example ( -- seq )
80 \ } parse-until dup { [ length 1 = ] [ first string? ] } 1&&
81 [ first example-lines ] [ >array ] if ;
83 : help-text? ( word -- ? )
85 $description $snippet $emphasis $strong $url $heading
86 $subheading $syntax $class-description
87 $error-description $var-description $contract $notes
88 $curious $deprecated $errors $side-effects $content
92 : help-values? ( word -- ? )
93 { $values $inputs $outputs } member-eq? ;
95 : help-examples? ( word -- ? )
96 { $examples } member-eq? ;
98 : help-example? ( word -- ? )
99 { $example $unchecked-example $code } member-eq? ;
104 scan-object dup \ } eq? [ drop { } ] [
106 { [ dup help-text? ] [ \ } parse-help-text ] }
107 { [ dup help-values? ] [ parse-help-values ] }
108 { [ dup help-example? ] [ parse-help-example ] }
109 { [ dup help-examples? ] [ parse-help-examples ] }
110 [ \ } parse-until >array ]
115 H{ { "{" POSTPONE: HELP{ } } [
116 scan-word bootstrap-word
117 [ >link save-location ]
118 [ [ parse-array-def ] dip set-word-help ]
124 scan-object scan-object
125 \ ; parse-help-text <article>
126 over add-article >link
127 ] dip remember-definition ;
130 current-vocab scan-object >>help changed-definition ;