From bb4960802b8776a61ebecfaa15b16b2c2df6c58e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 1 Dec 2005 05:53:12 +0000 Subject: [PATCH] initial checkin of help system code --- TODO.FACTOR.txt | 14 +++++ library/bootstrap/boot-stage2.factor | 2 +- library/help/help.factor | 91 ++++++++++++++++++++++++++++ library/help/load.factor | 9 +++ library/help/markup.factor | 50 +++++++++++++++ 5 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 library/help/help.factor create mode 100644 library/help/load.factor create mode 100644 library/help/markup.factor diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index d2ca233308..29d99ac634 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,5 +1,19 @@ + 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 interpreter unit test - intrinsic char-slot set-char-slot for x86 diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index c2a0cad0a2..5b961ec53b 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -30,7 +30,7 @@ t [ "/library/opengl/load.factor" "/library/freetype/load.factor" "/library/ui/load.factor" - "/library/help/tutorial.factor" + "/library/help/load.factor" ] pull-in ! Handle -libraries:... overrides diff --git a/library/help/help.factor b/library/help/help.factor new file mode 100644 index 0000000000..d89245057a --- /dev/null +++ b/library/help/help.factor @@ -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 -- ) +
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 -- ) + 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 diff --git a/library/help/load.factor b/library/help/load.factor new file mode 100644 index 0000000000..786250c6f7 --- /dev/null +++ b/library/help/load.factor @@ -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 diff --git a/library/help/markup.factor b/library/help/markup.factor new file mode 100644 index 0000000000..c5cff7cd69 --- /dev/null +++ b/library/help/markup.factor @@ -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 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 presented set + dup [ help ] curry outline set + ] make-hash [ article-title $subheading ] with-style terpri ; + +: $link ( name -- ) + first dup presented associate + [ article-title print-element ] with-style ; + +: $glossary ( element -- ) + first dup presented associate + [ print-element ] with-style ;