2005-12-01 00:53:12 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: help
|
2005-12-19 02:12:40 -05:00
|
|
|
USING: arrays gadgets gadgets-panes gadgets-presentations
|
2005-12-22 22:26:54 -05:00
|
|
|
hashtables inspector io kernel lists namespaces prettyprint
|
2005-12-30 03:57:38 -05:00
|
|
|
sequences strings styles vectors words ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: uncons* dup first swap 1 swap tail ;
|
|
|
|
|
|
|
|
: unswons* uncons* swap ;
|
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
! Simple markup language.
|
|
|
|
|
|
|
|
! <element> ::== <string> | <simple-element> | <fancy-element>
|
|
|
|
! <simple-element> ::== { <element>* }
|
|
|
|
! <fancy-element> ::== { <type> <element> }
|
|
|
|
|
|
|
|
! Element types are words whose name begins with $.
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
PREDICATE: array simple-element
|
|
|
|
dup empty? [ drop t ] [ first word? not ] if ;
|
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: write-term ( string -- )
|
|
|
|
dup terms get hash [
|
|
|
|
dup <term> presented associate [ format* ] with-style
|
|
|
|
] [
|
|
|
|
format*
|
|
|
|
] if ;
|
|
|
|
|
2005-12-19 23:18:15 -05:00
|
|
|
M: string print-element
|
2005-12-28 20:25:17 -05:00
|
|
|
" " split [ write-term ] [ bl ] interleave ;
|
2005-12-19 02:12:40 -05:00
|
|
|
|
|
|
|
M: array print-element
|
2005-12-28 20:25:17 -05:00
|
|
|
unswons* execute ;
|
2005-12-19 02:12:40 -05:00
|
|
|
|
2005-12-29 19:01:19 -05:00
|
|
|
M: word print-element
|
|
|
|
{ } swap execute ;
|
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
: ($span) ( content style -- )
|
2005-12-19 02:12:40 -05:00
|
|
|
[ print-element ] with-style ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: ($block) ( content style -- )
|
2005-12-19 23:18:15 -05:00
|
|
|
terpri*
|
|
|
|
[ [ print-element ] with-nesting* ] with-style
|
|
|
|
terpri* ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
|
|
|
! Some spans
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $heading heading-style ($block) ;
|
|
|
|
|
|
|
|
: $subheading subheading-style ($block) ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: $snippet snippet-style ($span) ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 23:18:15 -05:00
|
|
|
: $emphasis emphasis-style ($span) ;
|
|
|
|
|
2005-12-22 21:44:15 -05:00
|
|
|
: $url url-style ($span) ;
|
|
|
|
|
2005-12-19 23:18:15 -05:00
|
|
|
: $terpri terpri drop ;
|
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
! Some blocks
|
2005-12-31 20:51:58 -05:00
|
|
|
M: simple-element print-element [ print-element ] each ;
|
2005-12-19 23:18:15 -05:00
|
|
|
|
2005-12-31 04:20:07 -05:00
|
|
|
: ($code) ( presentation quot -- )
|
|
|
|
terpri*
|
2005-12-28 20:25:17 -05:00
|
|
|
code-style [
|
2005-12-31 04:20:07 -05:00
|
|
|
>r current-style swap presented pick set-hash r>
|
|
|
|
with-nesting
|
2005-12-28 20:25:17 -05:00
|
|
|
] with-style
|
2005-12-31 04:20:07 -05:00
|
|
|
terpri* ; inline
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: $code ( content -- )
|
2005-12-31 04:20:07 -05:00
|
|
|
first dup <input> [ format* ] ($code) ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
|
|
|
: $synopsis ( content -- )
|
2005-12-31 20:51:58 -05:00
|
|
|
first dup
|
|
|
|
word-vocabulary [ "Vocabulary" $subheading $snippet ] when*
|
|
|
|
stack-effect [ "Stack effect" $subheading $snippet ] when*
|
|
|
|
terpri* ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
|
|
|
: $values ( content -- )
|
|
|
|
"Arguments and values" $subheading [
|
|
|
|
unswons* $emphasis " -- " format* print-element terpri*
|
|
|
|
] each ;
|
|
|
|
|
|
|
|
: $description ( content -- )
|
|
|
|
"Description" $subheading print-element ;
|
|
|
|
|
2005-12-29 19:01:19 -05:00
|
|
|
: $contract ( content -- )
|
|
|
|
"Contract" $subheading print-element ;
|
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: $examples ( content -- )
|
2005-12-31 04:20:07 -05:00
|
|
|
"Examples" $subheading print-element ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
|
|
|
: $see-also ( content -- )
|
|
|
|
"See also" $subheading [ pprint bl ] each ;
|
|
|
|
|
|
|
|
: $see ( content -- )
|
2005-12-31 04:20:07 -05:00
|
|
|
terpri*
|
|
|
|
code-style [ [ first see ] with-nesting* ] with-style
|
|
|
|
terpri* ;
|
|
|
|
|
|
|
|
: $example ( content -- )
|
|
|
|
first2 swap dup <input>
|
|
|
|
[ format* "\n==> " format* format* ] ($code) ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
! Some links
|
2005-12-02 01:02:08 -05:00
|
|
|
TUPLE: link name ;
|
|
|
|
|
|
|
|
M: link article-title link-name article-title ;
|
|
|
|
|
|
|
|
M: link article-content link-name article-content ;
|
|
|
|
|
2005-12-22 22:26:54 -05:00
|
|
|
M: link summary ( term -- string )
|
|
|
|
"An article named \"" swap article-title "\"" append3 ;
|
|
|
|
|
2005-12-02 01:02:08 -05:00
|
|
|
DEFER: help
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: ($link) dup article-title swap ;
|
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
: $subsection ( object -- )
|
2005-12-22 22:26:54 -05:00
|
|
|
terpri*
|
2005-12-31 20:51:58 -05:00
|
|
|
subsection-style [
|
2005-12-28 20:25:17 -05:00
|
|
|
first <link> ($link) dup [ link-name (help) ] curry
|
2005-12-19 02:12:40 -05:00
|
|
|
simple-outliner
|
|
|
|
] with-style ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $link ( article -- ) first <link> ($link) simple-object ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $glossary ( element -- ) first <term> ($link) simple-object ;
|
2005-12-30 03:57:38 -05:00
|
|
|
|
|
|
|
: $definition ( content -- )
|
|
|
|
"Definition" $subheading $see ;
|
|
|
|
|
|
|
|
: $predicate ( content -- )
|
|
|
|
{ { "object" "an object" } } $values
|
|
|
|
"Tests if the top of the stack is " $description
|
|
|
|
dup first word-name a/an print-element $link
|
|
|
|
"." print-element ;
|
|
|
|
|
|
|
|
: $list ( content -- )
|
|
|
|
terpri* [ "- " format* print-element terpri* ] each ;
|
|
|
|
|
|
|
|
: $safety ( content -- )
|
|
|
|
"Memory safety" $subheading print-element ;
|
|
|
|
|
|
|
|
: $errors ( content -- )
|
|
|
|
"Errors" $subheading print-element ;
|
|
|
|
|
|
|
|
: $side-effects ( content -- )
|
|
|
|
"Side effects" $subheading "Modifies " print-element
|
|
|
|
[ $snippet ] [ "," format* bl ] interleave ;
|
|
|
|
|
|
|
|
: $notes ( content -- )
|
|
|
|
"Notes" $subheading print-element ;
|