2006-01-06 02:04:42 -05:00
|
|
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
2006-01-26 23:01:14 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-06-05 22:50:16 -04:00
|
|
|
USING: arrays generic hashtables inspector io kernel namespaces
|
2006-01-09 01:34:23 -05:00
|
|
|
parser prettyprint sequences strings styles vectors words ;
|
2006-06-20 18:31:48 -04:00
|
|
|
IN: help
|
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 $.
|
|
|
|
|
2006-06-22 01:57:43 -04:00
|
|
|
PREDICATE: array simple-element
|
|
|
|
dup empty? [ drop t ] [ first word? not ] if ;
|
|
|
|
|
|
|
|
M: simple-element elements* [ elements* ] each-with ;
|
|
|
|
|
|
|
|
M: object elements* 2drop ;
|
|
|
|
|
|
|
|
M: array elements*
|
|
|
|
[ [ elements* ] each-with ] 2keep
|
|
|
|
[ first eq? ] keep swap [ , ] [ drop ] if ;
|
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
SYMBOL: last-element
|
|
|
|
SYMBOL: span
|
|
|
|
SYMBOL: block
|
|
|
|
SYMBOL: table
|
|
|
|
|
|
|
|
: last-span? last-element get span eq? ;
|
|
|
|
: last-block? last-element get block eq? ;
|
|
|
|
|
|
|
|
: ($span) ( quot -- )
|
|
|
|
last-block? [ terpri ] when
|
|
|
|
span last-element set
|
|
|
|
call ; inline
|
|
|
|
|
2006-06-06 00:35:12 -04:00
|
|
|
M: simple-element print-element [ print-element ] each ;
|
2006-06-20 18:31:48 -04:00
|
|
|
M: string print-element [ write ] ($span) ;
|
2006-05-18 22:07:00 -04:00
|
|
|
M: array print-element unclip execute ;
|
2006-01-21 02:37:39 -05:00
|
|
|
M: word print-element { } swap execute ;
|
2005-12-29 19:01:19 -05:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: print-element* ( element style -- )
|
|
|
|
[ print-element ] with-style ;
|
|
|
|
|
|
|
|
: with-default-style ( quot -- )
|
|
|
|
default-style [
|
|
|
|
last-element off
|
|
|
|
H{ } swap with-nesting
|
|
|
|
] with-style ; inline
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: print-content ( element -- )
|
|
|
|
last-element off
|
|
|
|
[ print-element ] with-default-style ;
|
2006-06-10 00:53:29 -04:00
|
|
|
|
2006-01-21 02:37:39 -05:00
|
|
|
: ($block) ( quot -- )
|
2006-06-20 18:31:48 -04:00
|
|
|
last-element get { f table } member? [ terpri ] unless
|
|
|
|
span last-element set
|
2006-01-21 02:37:39 -05:00
|
|
|
call
|
2006-06-20 18:31:48 -04:00
|
|
|
block last-element set ; inline
|
2005-12-01 00:53:12 -05:00
|
|
|
|
|
|
|
! Some spans
|
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: $snippet [ snippet-style print-element* ] ($span) ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: $emphasis [ emphasis-style print-element* ] ($span) ;
|
2005-12-19 23:18:15 -05:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: $url [ url-style print-element* ] ($span) ;
|
2005-12-22 21:44:15 -05:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: $terpri terpri terpri drop ;
|
2005-12-19 23:18:15 -05:00
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
! Some blocks
|
2006-06-20 18:31:48 -04:00
|
|
|
: ($heading)
|
|
|
|
last-element get [ terpri ] when ($block) ; inline
|
2006-06-16 23:12:40 -04:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: $heading
|
|
|
|
[ heading-style print-element* ] ($heading) ;
|
2005-12-19 23:18:15 -05:00
|
|
|
|
2005-12-31 04:20:07 -05:00
|
|
|
: ($code) ( presentation quot -- )
|
2006-01-21 02:37:39 -05:00
|
|
|
[
|
|
|
|
code-style [
|
2006-06-20 18:31:48 -04:00
|
|
|
last-element off
|
|
|
|
>r presented associate code-style hash-union r>
|
|
|
|
with-nesting
|
2006-01-21 02:37:39 -05:00
|
|
|
] with-style
|
|
|
|
] ($block) ; inline
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: $code ( content -- )
|
2006-06-14 01:47:28 -04:00
|
|
|
"\n" join dup <input> [ write ] ($code) ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
2006-01-21 02:37:39 -05:00
|
|
|
: $vocabulary ( content -- )
|
2006-06-17 01:03:56 -04:00
|
|
|
first word-vocabulary
|
|
|
|
[ "Vocabulary" $heading $snippet ] when* ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
|
|
|
: $description ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Description" $heading print-element ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
2005-12-29 19:01:19 -05:00
|
|
|
: $contract ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Contract" $heading print-element ;
|
2005-12-29 19:01:19 -05:00
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: $examples ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Examples" $heading print-element ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
2006-06-16 23:12:40 -04:00
|
|
|
: $example ( content -- )
|
|
|
|
1 swap cut* swap "\n" join dup <input> [
|
|
|
|
input-style format terpri print-element
|
|
|
|
] ($code) ;
|
|
|
|
|
|
|
|
: $markup-example ( content -- )
|
|
|
|
first dup unparse " print-element" append 1array $code
|
|
|
|
print-element ;
|
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: $warning ( content -- )
|
2006-01-21 02:37:39 -05:00
|
|
|
[
|
2006-06-14 01:47:28 -04:00
|
|
|
warning-style [
|
2006-06-20 18:31:48 -04:00
|
|
|
last-element off
|
2006-06-04 02:00:59 -04:00
|
|
|
"Warning" $heading print-element
|
2006-01-21 02:37:39 -05:00
|
|
|
] with-nesting
|
2006-06-20 18:31:48 -04:00
|
|
|
] ($heading) ;
|
2006-01-06 02:04:42 -05:00
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
! Some links
|
2005-12-02 01:02:08 -05:00
|
|
|
M: link article-title link-name article-title ;
|
|
|
|
M: link article-content link-name article-content ;
|
2006-06-17 01:03:56 -04:00
|
|
|
M: link summary "Link: " swap link-name append ;
|
2006-06-05 23:26:44 -04:00
|
|
|
|
2006-06-17 02:10:28 -04:00
|
|
|
: >link ( obj -- obj ) dup word? [ <link> ] unless ;
|
|
|
|
|
2006-03-26 16:36:05 -05:00
|
|
|
: ($subsection) ( quot object -- )
|
|
|
|
subsection-style [
|
2006-06-17 02:10:28 -04:00
|
|
|
[ swap curry ] keep dup article-title swap >link
|
2006-06-14 01:47:28 -04:00
|
|
|
rot write-outliner
|
2006-03-26 16:36:05 -05:00
|
|
|
] with-style ;
|
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: $link ( article -- )
|
2006-06-20 18:31:48 -04:00
|
|
|
first link-style [
|
|
|
|
dup article-title swap >link write-object
|
|
|
|
] with-style ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2006-06-16 23:12:40 -04:00
|
|
|
: textual-list ( seq quot -- )
|
|
|
|
[ ", " print-element ] interleave ; inline
|
|
|
|
|
2006-06-08 18:06:38 -04:00
|
|
|
: $links ( content -- )
|
2006-06-20 18:31:48 -04:00
|
|
|
[ [ 1array $link ] textual-list ] ($span) ;
|
2006-06-08 18:06:38 -04:00
|
|
|
|
2006-01-02 16:35:37 -05:00
|
|
|
: $see-also ( content -- )
|
2006-06-08 18:06:38 -04:00
|
|
|
"See also" $heading $links ;
|
2006-01-02 16:35:37 -05:00
|
|
|
|
2006-06-22 01:57:43 -04:00
|
|
|
: $where ( article -- )
|
|
|
|
where dup empty? [
|
|
|
|
drop
|
|
|
|
] [
|
|
|
|
[
|
|
|
|
where-style [
|
|
|
|
"Parent topics: " write $links
|
|
|
|
] with-style
|
|
|
|
] ($block)
|
|
|
|
] if ;
|
|
|
|
|
2006-06-09 21:55:37 -04:00
|
|
|
: $table ( content -- )
|
2006-06-20 18:31:48 -04:00
|
|
|
[
|
|
|
|
table-style [
|
|
|
|
H{ { table-gap { 5 5 0 } } }
|
|
|
|
[ print-element ] tabular-output
|
|
|
|
] with-style
|
|
|
|
] ($block) table last-element set ;
|
2006-06-08 00:38:34 -04:00
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: $values ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Arguments and values" $heading
|
2006-06-16 23:12:40 -04:00
|
|
|
[ unclip \ $snippet swap 2array swap 2array ] map $table ;
|
2006-01-06 02:04:42 -05:00
|
|
|
|
2006-01-06 23:10:02 -05:00
|
|
|
: $predicate ( content -- )
|
|
|
|
{ { "object" "an object" } } $values
|
2006-01-21 02:37:39 -05:00
|
|
|
[
|
|
|
|
"Tests if the object is an instance of the " ,
|
|
|
|
{ $link } swap append ,
|
|
|
|
" class." ,
|
|
|
|
] { } make $description ;
|
2005-12-30 03:57:38 -05:00
|
|
|
|
2006-06-08 00:38:34 -04:00
|
|
|
: $list ( content -- ) [ "-" swap 2array ] map $table ;
|
2005-12-30 03:57:38 -05:00
|
|
|
|
|
|
|
: $errors ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Errors" $heading print-element ;
|
2005-12-30 03:57:38 -05:00
|
|
|
|
|
|
|
: $side-effects ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Side effects" $heading "Modifies " print-element
|
2006-01-02 01:04:02 -05:00
|
|
|
[ $snippet ] textual-list ;
|
2005-12-30 03:57:38 -05:00
|
|
|
|
|
|
|
: $notes ( content -- )
|
2006-06-04 02:00:59 -04:00
|
|
|
"Notes" $heading print-element ;
|
2006-01-06 22:42:07 -05:00
|
|
|
|
2006-06-20 18:31:48 -04:00
|
|
|
: ($see) ( word -- )
|
|
|
|
code-style [ code-style [ see ] with-nesting ] with-style ;
|
|
|
|
|
|
|
|
: $see ( content -- ) first ($see) ;
|
2006-06-12 02:41:19 -04:00
|
|
|
|
|
|
|
: $definition ( content -- )
|
2006-06-20 18:31:48 -04:00
|
|
|
"Definition" $heading ($see) ;
|
2006-06-12 02:41:19 -04:00
|
|
|
|
2006-06-06 21:29:09 -04:00
|
|
|
: $curious ( content -- )
|
|
|
|
"For the curious..." $heading print-element ;
|
|
|
|
|
|
|
|
: $references ( content -- )
|
|
|
|
"References" $heading
|
|
|
|
unclip print-element [ \ $link swap 2array ] map $list ;
|
|
|
|
|
2006-01-06 22:42:07 -05:00
|
|
|
: $shuffle ( content -- )
|
|
|
|
drop
|
|
|
|
"Shuffle word. Re-arranges the stack according to the stack effect pattern." $description ;
|
2006-01-08 20:41:31 -05:00
|
|
|
|
|
|
|
: $low-level-note
|
|
|
|
drop
|
2006-06-16 23:12:40 -04:00
|
|
|
"Calling this word directly is not necessary in most cases. Higher-level words call it automatically." $notes ;
|
2006-01-12 00:34:56 -05:00
|
|
|
|
|
|
|
: $values-x/y
|
2006-01-12 01:08:45 -05:00
|
|
|
drop
|
2006-01-12 00:34:56 -05:00
|
|
|
{ { "x" "a complex number" } { "y" "a complex number" } } $values ;
|
2006-01-16 02:48:15 -05:00
|
|
|
|
|
|
|
: $io-error
|
2006-01-21 02:37:39 -05:00
|
|
|
drop
|
2006-01-16 02:48:15 -05:00
|
|
|
"Throws an error if the I/O operation fails." $errors ;
|
2006-06-12 03:21:08 -04:00
|
|
|
|
2006-06-12 03:23:09 -04:00
|
|
|
: sort-articles ( seq -- assoc )
|
|
|
|
[ [ article-title ] keep 2array ] map
|
|
|
|
[ [ first ] 2apply <=> ] sort
|
|
|
|
[ second ] map ;
|
|
|
|
|
2006-06-12 03:21:08 -04:00
|
|
|
: help-outliner ( seq quot -- | quot: obj -- )
|
|
|
|
swap sort-articles [ ($subsection) terpri ] each-with ;
|