diff --git a/extra/ctags/etags/etags-tests.factor b/extra/ctags/etags/etags-tests.factor index 53e8f99aaf..8d5fc0ee02 100644 --- a/extra/ctags/etags/etags-tests.factor +++ b/extra/ctags/etags/etags-tests.factor @@ -1,4 +1,4 @@ -USING: kernel ctags.etags tools.test io.backend sequences arrays prettyprint hashtables assocs ; +USING: kernel ctags ctags.etags tools.test io.backend sequences arrays prettyprint hashtables assocs ; IN: ctags.etags.tests @@ -15,27 +15,27 @@ IN: ctags.etags.tests [ "path" ] [ { if { "path" 1 } } ctag-path ] unit-test [ V{ } ] -[ "path" H{ } clone ctag-at ] unit-test +[ "path" H{ } clone etag-at ] unit-test [ V{ if { "path" 1 } } ] -[ "path" H{ { "path" V{ if { "path" 1 } } } } ctag-at ] unit-test +[ "path" H{ { "path" V{ if { "path" 1 } } } } etag-at ] unit-test [ { if 28 } ] -[ { if { "resource:core/kernel/kernel.factor" 28 } } ctag-value ] unit-test +[ { if { "resource:core/kernel/kernel.factor" 28 } } etag-pair ] unit-test -[ V{ } ] [ { if { "path" 1 } } H{ } clone ctag-hashvalue ] unit-test +[ V{ } ] [ { if { "path" 1 } } H{ } clone etag-vector ] unit-test [ V{ if { "path" 1 } } ] [ { if { "path" 1 } } { { "path" V{ if { "path" 1 } } } } >hashtable - ctag-hashvalue + etag-vector ] unit-test [ H{ { "path" V{ { if 1 } } } } ] -[ { if { "path" 1 } } H{ } clone ctag-add ] unit-test +[ { if { "path" 1 } } H{ } clone [ etag-add ] keep ] unit-test [ H{ { "path" V{ { if 1 } } } } ] -[ { { if { "path" 1 } } } ctag-hash ] unit-test +[ { { if { "path" 1 } } } etag-hash ] unit-test [ "if28,704" ] [ "resource:core/kernel/kernel.factor" file>lines { if 28 } etag ] unit-test diff --git a/extra/ctags/etags/etags.factor b/extra/ctags/etags/etags.factor index f2d7d7e174..b3ad879481 100644 --- a/extra/ctags/etags/etags.factor +++ b/extra/ctags/etags/etags.factor @@ -8,25 +8,25 @@ io.encodings.ascii io.files math math.parser namespaces strings locals shuffle io.backend arrays ; IN: ctags.etags -: ctag-path ( alist -- path ) - second first ; - -: ctag-at ( key hash -- vector ) +: etag-at ( key hash -- vector ) at [ V{ } clone ] unless* ; -: ctag-hashvalue ( alist hash -- vector ) - [ ctag-path ] dip ctag-at ; +: etag-vector ( alist hash -- vector ) + [ ctag-path ] dip etag-at ; -: ctag-value ( ctag -- seq ) - dup [ first , second second , ] { } make ; +: etag-pair ( ctag -- seq ) + dup [ + first , + second second , + ] { } make ; -: ctag-add ( ctag hash -- hash ) - [ ctag-hashvalue ] 2keep [ - dup ctag-path [ ctag-value suffix ] dip - ] dip [ set-at ] keep ; +: etag-add ( ctag hash -- ) + [ etag-vector ] 2keep [ + [ etag-pair ] [ ctag-path ] bi [ suffix ] dip + ] dip set-at ; -: ctag-hash ( seq -- hash ) - H{ } clone swap [ swap ctag-add ] each ; +: etag-hash ( seq -- hash ) + H{ } clone swap [ swap [ etag-add ] keep ] each ; : lines>bytes ( seq n -- bytes ) head 0 [ length 1+ + ] reduce ; @@ -43,10 +43,7 @@ IN: ctags.etags 1- lines>bytes number>string % ] "" make ; -: etag-entry ( alist -- alist array ) - [ first ] keep swap [ file>lines ] keep 2array ; - -: vector-length ( vector -- n ) +: etag-length ( vector -- n ) 0 [ length + ] reduce ; :
( n path -- str ) @@ -60,15 +57,14 @@ IN: ctags.etags normalize-path
prefix 1 HEX: 0c prefix ; -SYMBOL: resource : etag-strings ( alist -- seq ) { } swap [ - etag-entry resource [ - second [ - resource get first swap etag - ] map dup vector-length - resource get second - ] with-variable + [ + [ first file>lines ] + [ second ] bi + [ etag ] with map + dup etag-length + ] keep first etag-header append ] each ; @@ -76,4 +72,4 @@ SYMBOL: resource [ etag-strings ] dip ascii set-file-lines ; : etags ( path -- ) - (ctags) sort-values ctag-hash >alist swap etags-write ; \ No newline at end of file + [ (ctags) sort-values etag-hash >alist ] dip etags-write ; \ No newline at end of file