initial checkin of help system code

cvs
Slava Pestov 2005-12-01 05:53:12 +00:00
parent 185116ea5d
commit bb4960802b
5 changed files with 165 additions and 1 deletions

View File

@ -1,5 +1,19 @@
+ 0.80: + 0.80:
word help sections:
- synopsis
- inputs and outputs
- exceptions
- see also
- examples
- side effects
- affected by (dynamic variables)
parsing word sections:
- syntax
- sort out types on 64-bit platforms
- malloc, free, realloc, memcpy: aliens
- check 'see' - check 'see'
- check interpreter unit test - check interpreter unit test
- intrinsic char-slot set-char-slot for x86 - intrinsic char-slot set-char-slot for x86

View File

@ -30,7 +30,7 @@ t [
"/library/opengl/load.factor" "/library/opengl/load.factor"
"/library/freetype/load.factor" "/library/freetype/load.factor"
"/library/ui/load.factor" "/library/ui/load.factor"
"/library/help/tutorial.factor" "/library/help/load.factor"
] pull-in ] pull-in
! Handle -libraries:... overrides ! Handle -libraries:... overrides

91
library/help/help.factor Normal file
View File

@ -0,0 +1,91 @@
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: help
USING: arrays gadgets-presentations hashtables io kernel
namespaces parser sequences strings styles words ;
! Markup
SYMBOL: style-stack
GENERIC: print-element
: with-style ( style quot -- )
swap style-stack get push call style-stack get pop* ; inline
: current-style ( -- style )
H{ } clone style-stack get [ dupd hash-update ] each ;
PREDICATE: array simple-element
dup empty? [ drop t ] [ first word? not ] if ;
M: string print-element current-style format ;
M: simple-element print-element [ print-element ] each ;
M: array print-element
dup first >r 1 swap tail r> execute ;
: default-style H{ { font "Sans Serif" } { font-size 14 } } ;
: with-markup ( quot -- )
[
default-style V{ } clone [ push ] keep style-stack set
call
] with-scope ; inline
! Help articles
SYMBOL: articles
TUPLE: article title content ;
: article ( name -- article ) articles get hash ;
: add-article ( name title element -- )
<article> swap articles get set-hash ;
M: string article-title article article-title ;
M: string article-content article article-content ;
! Word help
M: word article-title "The " swap word-name " word" append3 ;
M: word article-content
dup "help" word-prop [ ] [
"No documentation found for " swap word-name append
] ?if ;
! Glossary of terms
SYMBOL: terms
TUPLE: term entry ;
M: term article-title term-entry ;
M: term article-content terms get hash ;
: help ( topic -- )
[
dup article-title $heading terpri terpri
article-content print-element terpri
] with-markup ;
: glossary ( name -- )
<term> help ;
: HELP:
scan-word
[ >array reverse "help" set-word-prop ] ; parsing
: ARTICLE:
[
>array reverse [ first2 2 ] keep
tail add-article
] ; parsing
[ word? ] "Show word documentation" [ help ] define-command
[ term? ] "Show term definition" [ help ] define-command
[ link? ] "Show article" [ help ] define-command
H{ } clone articles set
H{ } clone terms set

9
library/help/load.factor Normal file
View File

@ -0,0 +1,9 @@
USING: io kernel parser sequences ;
[
"/library/help/help.factor"
"/library/help/markup.factor"
"/library/help/tutorial.factor"
] [
dup print run-resource
] each

View File

@ -0,0 +1,50 @@
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: help
USING: gadgets gadgets-panes gadgets-presentations hashtables io
kernel lists namespaces prettyprint sequences styles ;
! Simple markup language.
! <element> ::== <string> | <simple-element> | <fancy-element>
! <simple-element> ::== { <element>* }
! <fancy-element> ::== { <type> <element> }
! Element types are words whose name begins with $.
: ($span) ( content style -- )
[ print-element ] with-style ; inline
: ($block) ( content style quot -- )
>r [ [ print-element ] make-pane ] with-style
dup r> call gadget. ; inline
: $see ( content -- ) first see ;
! Some spans
: $heading H{ { font "Serif" } { font-size 24 } } ($span) ;
: $subheading H{ { font "Serif" } { font-size 18 } } ($span) ;
: $parameter H{ { font "Monospaced" } { font-size 12 } } ($span) ;
! Some blocks
: $code
H{ { font "Monospaced" } { font-size 12 } }
[ T{ solid f { 0.9 0.9 0.9 1 } } swap set-gadget-interior ]
($block) ;
! Some links
: $subsection ( object -- )
first [
dup <link> presented set
dup [ help ] curry outline set
] make-hash [ article-title $subheading ] with-style terpri ;
: $link ( name -- )
first dup <link> presented associate
[ article-title print-element ] with-style ;
: $glossary ( element -- )
first dup <term> presented associate
[ print-element ] with-style ;