Rework etags vocab. Remove use of local variable shuffle words, use

combinators instead. Rename some words and update testsuite accordingly
db4
Alfredo Beaumont 2008-07-13 17:11:11 +02:00
parent 6c5e73898f
commit f05aabdf28
2 changed files with 30 additions and 34 deletions

View File

@ -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

View File

@ -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 ;
: <header> ( n path -- str )
@ -60,15 +57,14 @@ IN: ctags.etags
normalize-path <header> prefix
1 HEX: 0c <string> 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 ;
[ (ctags) sort-values etag-hash >alist ] dip etags-write ;