]> gitweb.factorcode.org Git - factor.git/blob - extra/ctags/etags/etags.factor
Switch to https urls
[factor.git] / extra / ctags / etags / etags.factor
1 ! Copyright (C) 2008 Alfredo Beaumont
2 ! See https://factorcode.org/license.txt for BSD license.
3
4 ! Emacs Etags generator
5 ! Alfredo Beaumont <alfredo.beaumont@gmail.com>
6 USING: arrays assocs ctags.private fry io.backend
7 io.encodings.ascii io.files kernel make math math.parser present
8 sequences sorting strings vocabs ;
9 IN: ctags.etags
10
11 <PRIVATE
12
13 : etag-hash ( alist -- hash )
14     H{ } clone [
15         '[ first2 swap [ 2array ] dip _ push-at ] assoc-each
16     ] keep ;
17
18 : lines>bytes ( lines -- bytes )
19     0 [ length 1 + + ] accumulate nip ;
20
21 : etag ( bytes seq -- str )
22     [
23         dup first present %
24         0x7f ,
25         second dup number>string %
26         "," %
27         1 - swap nth number>string %
28     ] "" make ;
29
30 : etag-header ( vec1 resource -- vec2 )
31     [
32         normalize-path %
33         "," %
34         dup sum-lengths number>string %
35     ] "" make prefix "\f" prefix ;
36
37 : make-etags ( alist -- seq )
38     V{ } clone swap [
39         over [
40             [ ascii file-lines lines>bytes ] dip
41             [ etag ] with map
42         ] dip etag-header append!
43     ] assoc-each ;
44
45 PRIVATE>
46
47 : etags ( -- etags )
48     all-words locations etag-hash sort-keys make-etags ;
49
50 : write-etags ( path -- )
51     [ etags ] dip ascii set-file-lines ;