ctags.etags: cleanup.

locals-and-roots
John Benediktsson 2016-04-19 08:40:42 -07:00
parent eb4bbab417
commit 55fda7140d
3 changed files with 42 additions and 131 deletions

View File

@ -5,12 +5,10 @@ ARTICLE: "etags" "Etags file"
{ $emphasis "Etags" } " generates a index file of every factor word in etags format as supported by emacs and other editors. More information can be found at " { $url "http://en.wikipedia.org/wiki/Ctags#Etags_2" } "."
{ $subsections
etags
etags-write
etag-strings
etag-header
write-etags
}
HELP: etags
HELP: write-etags
{ $values { "path" string } }
{ $description "Generates a index file in etags format and stores in " { $snippet "path" } "." }
{ $examples
@ -21,21 +19,4 @@ HELP: etags
}
} ;
HELP: etags-write
{ $values { "alist" sequence }
{ "path" string } }
{ $description "Stores a " { $snippet "alist" } " in " { $snippet "path" } ". " { $snippet "alist" } " must be an association list with etags format: its key must be a resource path and its value a vector, containing pairs of words and lines" }
{ $examples
{ $unchecked-example
"USING: kernel etags.ctags ;"
"{ { \"resource:extra/unix/unix.factor\" V{ { dup2 91 } } } } \"ETAGS\" etags-write"
""
}
} ;
HELP: etag-strings
{ $values { "alist" sequence }
{ "seq" sequence } }
{ $description "Converts an " { $snippet "alist" } " with etag format (a path as key and a vector containing word/line pairs) in a " { $snippet "seq" } " of strings." } ;
ABOUT: "etags" ;

View File

@ -1,48 +1,6 @@
USING: kernel ctags ctags.etags tools.test io.backend sequences arrays prettyprint hashtables assocs ;
USING: ctags.etags.private kernel tools.test ;
IN: ctags.etags.tests
! etag-at
{ t }
[
V{ }
"path" H{ } clone etag-at =
] unit-test
{ t }
[
V{ if { "path" 1 } }
"path" H{ { "path" V{ if { "path" 1 } } } } etag-at =
] unit-test
! etag-vector
{ t }
[
V{ }
{ if { "path" 1 } } H{ } clone etag-vector =
] unit-test
{ t }
[
V{ if { "path" 1 } }
{ if { "path" 1 } }
{ { "path" V{ if { "path" 1 } } } } >hashtable
etag-vector =
] unit-test
! etag-pair
{ t }
[
{ if 28 }
{ if { "resource:core/kernel/kernel.factor" 28 } } etag-pair =
] unit-test
! etag-add
{ t }
[
H{ { "path" V{ { if 1 } } } }
{ if { "path" 1 } } H{ } clone [ etag-add ] keep =
] unit-test
! etag-hash
{ t }
[
@ -50,16 +8,9 @@ IN: ctags.etags.tests
{ { if { "path" 1 } } } etag-hash =
] unit-test
! line-bytes (note that for each line implicit \n is counted)
{ t }
[
17
{ "1234567890" "12345" } 2 lines>bytes =
] unit-test
! etag
{ t }
[
"if2,11"
{ "1234567890" "12345" } { if 2 } etag =
{ 0 11 } { if 2 } etag =
] unit-test

View File

@ -3,70 +3,49 @@
! Emacs Etags generator
! Alfredo Beaumont <alfredo.beaumont@gmail.com>
USING: kernel sequences sorting assocs words prettyprint ctags
io.encodings.ascii io.files math math.parser namespaces make
strings shuffle io.backend arrays present ;
USING: arrays assocs ctags.private fry io.backend
io.encodings.ascii io.files kernel make math math.parser present
sequences sorting strings vocabs ;
IN: ctags.etags
: etag-at ( key hash -- vector )
at [ V{ } clone ] unless* ;
<PRIVATE
: etag-vector ( alist hash -- vector )
[ ctag-path ] dip etag-at ;
: etag-hash ( alist -- hash )
H{ } clone [
'[ first2 swap [ 2array ] dip _ push-at ] assoc-each
] keep ;
: etag-pair ( ctag -- seq )
dup [
first ,
second second ,
] { } make ;
: lines>bytes ( lines -- bytes )
0 [ length 1 + + ] accumulate nip ;
: etag-add ( ctag hash -- )
[ etag-vector ] 2keep [
[ etag-pair ] [ ctag-path ] bi [ suffix ] dip
] dip set-at ;
: etag-hash ( seq -- hash )
H{ } clone swap [ swap [ etag-add ] keep ] each ;
: lines>bytes ( seq n -- bytes )
head 0 [ length 1 + + ] reduce ;
: file>lines ( path -- lines )
ascii file-lines ;
: etag ( lines seq -- str )
: etag ( bytes seq -- str )
[
dup first present %
1 0x7f <string> %
0x7f ,
second dup number>string %
1 CHAR: , <string> %
1 - lines>bytes number>string %
"," %
1 - swap nth number>string %
] "" make ;
: (etag-header) ( n path -- str )
: etag-header ( vec1 resource -- vec2 )
[
%
1 CHAR: , <string> %
number>string %
] "" make ;
normalize-path %
"," %
dup sum-lengths number>string %
] "" make prefix "\f" prefix ;
: etag-header ( vec1 n resource -- vec2 )
normalize-path (etag-header) prefix
1 0x0c <string> prefix ;
: etag-strings ( alist -- seq )
{ } swap [
[
[ first file>lines ]
[ second ] bi
: make-etags ( alist -- seq )
V{ } clone swap [
over [
[ ascii file-lines lines>bytes ] dip
[ etag ] with map
dup sum-lengths
] keep first
etag-header append
] each ;
] dip etag-header append!
] assoc-each ;
: etags-write ( alist path -- )
[ etag-strings ] dip ascii set-file-lines ;
PRIVATE>
: etags ( path -- )
[ (ctags) sort-values etag-hash >alist ] dip etags-write ;
: etags ( -- etags )
all-words locations etag-hash sort-keys make-etags ;
: write-etags ( path -- )
[ etags ] dip ascii set-file-lines ;