]> gitweb.factorcode.org Git - factor.git/blob - extra/fuel/xref/xref.factor
Merge branch 'emacs' of http://git.hacks-galore.org/jao/factor
[factor.git] / extra / fuel / xref / xref.factor
1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
3
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
7 words ;
8
9 IN: fuel.xref
10
11 <PRIVATE
12
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 ;
16
17 : get-loc ( object -- loc ) normalize-loc 2array ;
18
19 : word>xref ( word -- xref )
20     [ name>> ] [ vocabulary>> ] [ where normalize-loc ] tri 4array ;
21
22 : vocab>xref ( vocab -- xref )
23     dup dup >vocab-link where normalize-loc 4array ;
24
25 : sort-xrefs ( seq -- seq' )
26     [ first ] sort-with ;
27
28 : format-xrefs ( seq -- seq' )
29     [ word? ] filter [ word>xref ] map ;
30
31 : filter-prefix ( seq prefix -- seq )
32     [ drop-prefix nip length 0 = ] curry filter prune ;
33
34 MEMO: (vocab-words) ( name -- seq )
35     >vocab-link words [ name>> ] map ;
36
37 : current-words ( -- seq )
38     manifest get
39     [ search-vocabs>> ] [ qualified-vocabs>> ] bi [ [ words>> ] map ] bi@
40     append H{ } [ assoc-union ] reduce keys ;
41
42 : vocabs-words ( names -- seq )
43     prune [ (vocab-words) ] map concat ;
44
45 PRIVATE>
46
47 : callers-xref ( word -- seq ) usage format-xrefs sort-xrefs ;
48
49 : callees-xref ( word -- seq ) uses format-xrefs sort-xrefs ;
50
51 : apropos-xref ( str -- seq ) words-matching format-xrefs ;
52
53 : vocab-xref ( vocab -- seq ) words format-xrefs ;
54
55 : word-location ( word -- loc ) where get-loc ;
56
57 : vocab-location ( vocab -- loc ) >vocab-link where get-loc ;
58
59 : vocab-uses-xref ( vocab -- seq ) vocab-uses [ vocab>xref ] map ;
60
61 : vocab-usage-xref ( vocab -- seq ) vocab-usage [ vocab>xref ] map ;
62
63 : doc-location ( word -- loc ) props>> "help-loc" swap at get-loc ;
64
65 : article-location ( name -- loc ) article loc>> get-loc ;
66
67 : get-vocabs ( -- seq ) all-vocab-names ;
68
69 : get-vocabs/prefix ( prefix -- seq ) get-vocabs swap filter-prefix ;
70
71 : get-vocabs-words/prefix ( prefix names/f -- seq )
72     [ vocabs-words ] [ current-words ] if* natural-sort swap filter-prefix ;