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" } "." { $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 { $subsections
etags etags
etags-write write-etags
etag-strings
etag-header
} }
HELP: etags HELP: write-etags
{ $values { "path" string } } { $values { "path" string } }
{ $description "Generates a index file in etags format and stores in " { $snippet "path" } "." } { $description "Generates a index file in etags format and stores in " { $snippet "path" } "." }
{ $examples { $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" ; 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 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 ! etag-hash
{ t } { t }
[ [
@ -50,16 +8,9 @@ IN: ctags.etags.tests
{ { if { "path" 1 } } } etag-hash = { { if { "path" 1 } } } etag-hash =
] unit-test ] unit-test
! line-bytes (note that for each line implicit \n is counted)
{ t }
[
17
{ "1234567890" "12345" } 2 lines>bytes =
] unit-test
! etag ! etag
{ t } { t }
[ [
"if2,11" "if2,11"
{ "1234567890" "12345" } { if 2 } etag = { 0 11 } { if 2 } etag =
] unit-test ] unit-test

View File

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