diff --git a/extra/ctags/etags/etags-docs.factor b/extra/ctags/etags/etags-docs.factor index a21ec232cc..5cd96d0c9f 100644 --- a/extra/ctags/etags/etags-docs.factor +++ b/extra/ctags/etags/etags-docs.factor @@ -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" ; diff --git a/extra/ctags/etags/etags-tests.factor b/extra/ctags/etags/etags-tests.factor index 01dd19a018..d0eeb499a7 100644 --- a/extra/ctags/etags/etags-tests.factor +++ b/extra/ctags/etags/etags-tests.factor @@ -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 diff --git a/extra/ctags/etags/etags.factor b/extra/ctags/etags/etags.factor index 90e3615ba3..2024467831 100644 --- a/extra/ctags/etags/etags.factor +++ b/extra/ctags/etags/etags.factor @@ -3,70 +3,49 @@ ! Emacs Etags generator ! Alfredo Beaumont -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* ; +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 ) - [ - dup first present % - 1 0x7f % - second dup number>string % - 1 CHAR: , % - 1 - lines>bytes number>string % - ] "" make ; - -: (etag-header) ( n path -- str ) - [ - % - 1 CHAR: , % - number>string % - ] "" make ; - -: etag-header ( vec1 n resource -- vec2 ) - normalize-path (etag-header) prefix - 1 0x0c prefix ; - -: etag-strings ( alist -- seq ) - { } swap [ +: etag ( bytes seq -- str ) [ - [ first file>lines ] - [ second ] bi - [ etag ] with map - dup sum-lengths - ] keep first - etag-header append - ] each ; + dup first present % + 0x7f , + second dup number>string % + "," % + 1 - swap nth number>string % + ] "" make ; -: etags-write ( alist path -- ) - [ etag-strings ] dip ascii set-file-lines ; +: etag-header ( vec1 resource -- vec2 ) + [ + normalize-path % + "," % + dup sum-lengths number>string % + ] "" make prefix "\f" prefix ; -: etags ( path -- ) - [ (ctags) sort-values etag-hash >alist ] dip etags-write ; +: make-etags ( alist -- seq ) + 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 ;