1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: accessors arrays assocs definitions help.topics io.pathnames
5 kernel math math.order memoize namespaces sequences sets sorting
6 tools.completion tools.crossref vocabs vocabs.parser vocabs.hierarchy
13 : normalize-loc ( seq -- path line )
14 [ dup length 0 > [ first (normalize-path) ] [ drop f ] if ]
15 [ dup length 1 > [ second ] [ drop 1 ] if ] bi ;
17 : get-loc ( object -- loc ) normalize-loc 2array ;
19 : word>xref ( word -- xref )
20 [ name>> ] [ vocabulary>> ] [ where normalize-loc ] tri 4array ;
22 : vocab>xref ( vocab -- xref )
23 dup dup >vocab-link where normalize-loc 4array ;
25 : sort-xrefs ( seq -- seq' )
26 [ [ first ] dip first <=> ] sort ; inline
28 : format-xrefs ( seq -- seq' )
29 [ word? ] filter [ word>xref ] map ; inline
31 : filter-prefix ( seq prefix -- seq )
32 [ drop-prefix nip length 0 = ] curry filter prune ; inline
34 MEMO: (vocab-words) ( name -- seq )
35 >vocab-link words [ name>> ] map ;
37 : current-words ( -- seq )
39 [ search-vocabs>> ] [ qualified-vocabs>> ] bi [ words>> ] bi@
40 assoc-union keys ; inline
42 : vocabs-words ( names -- seq )
43 prune [ (vocab-words) ] map concat ; inline
47 : callers-xref ( word -- seq ) usage format-xrefs sort-xrefs ;
49 : callees-xref ( word -- seq ) uses format-xrefs sort-xrefs ;
51 : apropos-xref ( str -- seq ) words-matching format-xrefs ;
53 : vocab-xref ( vocab -- seq ) words format-xrefs ;
55 : word-location ( word -- loc ) where get-loc ;
57 : vocab-location ( vocab -- loc ) >vocab-link where get-loc ;
59 : vocab-uses-xref ( vocab -- seq ) vocab-uses [ vocab>xref ] map ;
61 : vocab-usage-xref ( vocab -- seq ) vocab-usage [ vocab>xref ] map ;
63 : doc-location ( word -- loc ) props>> "help-loc" swap at get-loc ;
65 : article-location ( name -- loc ) article loc>> get-loc ;
67 : get-vocabs ( -- seq ) all-vocabs-seq [ vocab-name ] map ;
69 : get-vocabs/prefix ( prefix -- seq ) get-vocabs swap filter-prefix ;
71 : get-vocabs-words/prefix ( prefix names/f -- seq )
72 [ vocabs-words ] [ current-words ] if* natural-sort swap filter-prefix ;