2006-06-17 01:03:56 -04:00
|
|
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: help
|
2006-08-02 16:53:26 -04:00
|
|
|
USING: arrays definitions errors generic graphs hashtables
|
|
|
|
inspector io kernel namespaces prettyprint sequences words ;
|
2006-06-17 01:03:56 -04:00
|
|
|
|
|
|
|
! Markup
|
2006-08-15 04:57:12 -04:00
|
|
|
GENERIC: print-element ( element -- )
|
2006-06-17 01:03:56 -04:00
|
|
|
|
|
|
|
! Help articles
|
|
|
|
SYMBOL: articles
|
|
|
|
|
2006-08-02 16:53:26 -04:00
|
|
|
TUPLE: article title content loc ;
|
2006-06-17 01:03:56 -04:00
|
|
|
|
2006-08-01 17:35:00 -04:00
|
|
|
TUPLE: no-article name ;
|
2006-08-15 03:01:24 -04:00
|
|
|
: no-article ( name -- * ) <no-article> throw ;
|
2006-08-01 17:35:00 -04:00
|
|
|
|
2006-06-17 01:03:56 -04:00
|
|
|
: article ( name -- article )
|
2006-08-01 17:35:00 -04:00
|
|
|
dup articles get hash [ ] [ no-article ] ?if ;
|
2006-06-17 01:03:56 -04:00
|
|
|
|
2006-06-22 22:36:56 -04:00
|
|
|
M: object article-title article article-title ;
|
|
|
|
M: object article-content article article-content ;
|
2006-06-17 01:03:56 -04:00
|
|
|
|
2006-08-02 16:53:26 -04:00
|
|
|
TUPLE: link name ;
|
|
|
|
|
|
|
|
M: link article-title link-name article-title ;
|
|
|
|
M: link article-content link-name article-content ;
|
|
|
|
M: link summary "Link: " swap link-name unparse append ;
|
|
|
|
|
2006-06-17 01:03:56 -04:00
|
|
|
! Special case: f help
|
|
|
|
M: f article-title drop \ f article-title ;
|
|
|
|
M: f article-content drop \ f article-content ;
|
2006-06-22 01:57:43 -04:00
|
|
|
|
2006-06-22 22:36:56 -04:00
|
|
|
: word-help ( word -- content ) "help" word-prop ;
|
|
|
|
|
2006-06-22 01:57:43 -04:00
|
|
|
: all-articles ( -- seq )
|
2006-06-22 22:36:56 -04:00
|
|
|
articles get hash-keys
|
|
|
|
all-words [ word-help ] subset append ;
|
2006-06-22 01:57:43 -04:00
|
|
|
|
|
|
|
GENERIC: elements* ( elt-type element -- )
|
|
|
|
|
|
|
|
: elements ( elt-type element -- seq ) [ elements* ] { } make ;
|
|
|
|
|
|
|
|
: collect-elements ( element seq -- elements )
|
|
|
|
[
|
|
|
|
[
|
|
|
|
swap elements [
|
2006-07-29 20:36:25 -04:00
|
|
|
1 tail [ dup set ] each
|
2006-06-22 01:57:43 -04:00
|
|
|
] each
|
|
|
|
] each-with
|
|
|
|
] make-hash hash-keys ;
|
|
|
|
|
|
|
|
SYMBOL: parent-graph
|
|
|
|
|
|
|
|
DEFER: $subsection
|
|
|
|
|
|
|
|
: children ( article -- seq )
|
|
|
|
article-content { $subsection } collect-elements ;
|
|
|
|
|
|
|
|
: parents ( article -- seq )
|
|
|
|
dup link? [ link-name ] when parent-graph get in-edges ;
|
|
|
|
|
2006-08-02 16:53:26 -04:00
|
|
|
: (doc-path) ( article -- )
|
2006-06-22 01:57:43 -04:00
|
|
|
dup , parents [ word? not ] subset dup empty?
|
2006-08-02 16:53:26 -04:00
|
|
|
[ drop ] [ [ (doc-path) ] each ] if ;
|
2006-06-22 01:57:43 -04:00
|
|
|
|
2006-08-02 16:53:26 -04:00
|
|
|
: doc-path ( article -- seq )
|
|
|
|
[ (doc-path) ] { } make 1 tail prune ;
|
2006-06-22 01:57:43 -04:00
|
|
|
|
|
|
|
: xref-article ( article -- )
|
|
|
|
[ children ] parent-graph get add-vertex ;
|
|
|
|
|
|
|
|
: unxref-article ( article -- )
|
|
|
|
[ children ] parent-graph get remove-vertex ;
|
|
|
|
|
2006-06-22 22:36:56 -04:00
|
|
|
: xref-help ( -- )
|
2006-06-22 01:57:43 -04:00
|
|
|
all-articles [ children ] parent-graph get build-graph ;
|
2006-08-02 16:53:26 -04:00
|
|
|
|
|
|
|
! Definition protocol
|
|
|
|
M: link where link-name article article-loc ;
|
|
|
|
|
|
|
|
M: link (synopsis)
|
|
|
|
\ ARTICLE: pprint-word
|
|
|
|
dup link-name pprint*
|
|
|
|
article-title pprint* ;
|
|
|
|
|
|
|
|
M: link definition article-content t ;
|
|
|
|
|
|
|
|
M: link see (see) ;
|
|
|
|
|
|
|
|
PREDICATE: link word-link link-name word? ;
|
|
|
|
|
|
|
|
M: word-link where link-name "help-loc" word-prop ;
|
|
|
|
|
|
|
|
M: word-link (synopsis)
|
|
|
|
\ HELP: pprint-word
|
|
|
|
link-name dup pprint-word
|
|
|
|
"stack-effect" word-prop pprint* ;
|
|
|
|
|
|
|
|
M: word-link definition
|
|
|
|
link-name "help" word-prop t ;
|
|
|
|
|
|
|
|
M: word-link see (see) ;
|