Merge branch 'ctags'

Conflicts:

	extra/wordtimer/wordtimer.factor
db4
Alfredo Beaumont 2008-07-13 18:50:53 +02:00
commit bda6fba99a
8 changed files with 264 additions and 13 deletions

View File

@ -1,4 +1,4 @@
USING: help.syntax help.markup kernel prettyprint sequences strings ;
USING: help.syntax help.markup kernel prettyprint sequences strings words math ;
IN: ctags
ARTICLE: "ctags" "Ctags file"
@ -6,7 +6,10 @@ ARTICLE: "ctags" "Ctags file"
{ $subsection ctags }
{ $subsection ctags-write }
{ $subsection ctag-strings }
{ $subsection ctag } ;
{ $subsection ctag }
{ $subsection ctag-word }
{ $subsection ctag-path }
{ $subsection ctag-lineno } ;
HELP: ctags ( path -- )
{ $values { "path" "a pathname string" } }
@ -57,4 +60,41 @@ HELP: ctag ( seq -- str )
}
} ;
HELP: ctag-lineno ( ctag -- n )
{ $values { "ctag" sequence }
{ "n" integer } }
{ $description "Provides de line number " { $snippet "n" } " from a sequence in ctag format " }
{ $examples
{ $example
"USING: kernel ctags prettyprint ;"
"{ if { \"resource:extra/unix/unix.factor\" 91 } } ctag-lineno ."
"91"
}
} ;
HELP: ctag-path ( ctag -- path )
{ $values { "ctag" sequence }
{ "path" string } }
{ $description "Provides a path string " { $snippet "path" } " from a sequence in ctag format" }
{ $examples
{ $example
"USING: kernel ctags prettyprint ;"
"{ if { \"resource:extra/unix/unix.factor\" 91 } } ctag-path ."
"\"resource:extra/unix/unix.factor\""
}
} ;
HELP: ctag-word ( ctag -- word )
{ $values { "ctag" sequence }
{ "word" word } }
{ $description "Provides the " { $snippet "word" } " from a sequence in ctag format " }
{ $examples
{ $example
"USING: kernel ctags prettyprint ;"
"{ if { \"resource:extra/unix/unix.factor\" 91 } } ctag-word ."
"if"
}
} ;
ABOUT: "ctags"

View File

@ -1,6 +1,21 @@
USING: kernel ctags tools.test io.backend sequences arrays prettyprint ;
IN: ctags.tests
[ t ] [
91
{ { if { "resource:extra/unix/unix.factor" 91 } } } ctag-lineno =
] unit-test
[ t ] [
"resource:extra/unix/unix.factor"
{ { if { "resource:extra/unix/unix.factor" 91 } } } ctag-path =
] unit-test
[ t ] [
if
{ { if { "resource:extra/unix/unix.factor" 91 } } } ctag-word =
] unit-test
[ t ] [
"if\t" "resource:extra/unix/unix.factor" normalize-path "\t91" 3append
{ if { "resource:extra/unix/unix.factor" 91 } } ctag =
@ -9,4 +24,5 @@ IN: ctags.tests
[ t ] [
"if\t" "resource:extra/unix/unix.factor" normalize-path "\t91" 3append 1array
{ { if { "resource:extra/unix/unix.factor" 91 } } } ctag-strings =
] unit-test
] unit-test

View File

@ -9,29 +9,36 @@ io.encodings.ascii math.parser vocabs definitions
namespaces words sorting ;
IN: ctags
: ctag-word ( ctag -- word )
first ;
: ctag-path ( ctag -- path )
second first ;
: ctag-lineno ( ctag -- n )
second second ;
: ctag ( seq -- str )
[
dup first ?word-name %
dup ctag-word ?word-name %
"\t" %
second dup first normalize-path %
dup ctag-path normalize-path %
"\t" %
second number>string %
ctag-lineno number>string %
] "" make ;
: ctag-strings ( seq1 -- seq2 )
{ } swap [ ctag suffix ] each ;
[ ctag ] map ;
: ctags-write ( seq path -- )
[ ctag-strings ] dip ascii set-file-lines ;
: (ctags) ( -- seq )
{ } all-words [
all-words [
dup where [
2array suffix
] [
drop
] if*
] each ;
2array
] when*
] map [ sequence? ] filter ;
: ctags ( path -- )
(ctags) sort-keys swap ctags-write ;

View File

@ -0,0 +1 @@
Alfredo Beaumont

View File

@ -0,0 +1,39 @@
USING: help.syntax help.markup kernel prettyprint sequences strings words math ;
IN: ctags.etags
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" } "."
{ $subsection etags }
{ $subsection etags-write }
{ $subsection etag-strings }
{ $subsection etag-header }
HELP: etags ( path -- )
{ $values { "path" string } }
{ $description "Generates a index file in etags format and stores in " { $snippet "path" } "." }
{ $examples
{ $unchecked-example
"USING: ctags.etags ;"
"\"ETAGS\" etags"
""
}
} ;
HELP: etags-write ( alist path -- )
{ $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 ( alist -- seq )
{ $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

@ -0,0 +1,72 @@
USING: kernel ctags ctags.etags tools.test io.backend sequences arrays prettyprint hashtables assocs ;
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 ]
[
H{ { "path" V{ { if 1 } } } }
{ { 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 =
] unit-test
! etag-length
[ t ]
[
14
V{ "if2,11" "if2,11" } etag-length =
] unit-test

View File

@ -0,0 +1,75 @@
! Copyright (C) 2008 Alfredo Beaumont
! See http://factorcode.org/license.txt for BSD license.
! 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 strings locals
shuffle io.backend arrays ;
IN: ctags.etags
: etag-at ( key hash -- vector )
at [ V{ } clone ] unless* ;
: etag-vector ( alist hash -- vector )
[ ctag-path ] dip etag-at ;
: etag-pair ( ctag -- seq )
dup [
first ,
second second ,
] { } make ;
: 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 ?word-name %
1 HEX: 7f <string> %
second dup number>string %
1 CHAR: , <string> %
1- lines>bytes number>string %
] "" make ;
: etag-length ( vector -- n )
0 [ length + ] reduce ;
: (etag-header) ( n path -- str )
[
%
1 CHAR: , <string> %
number>string %
] "" make ;
: etag-header ( vec1 n resource -- vec2 )
normalize-path (etag-header) prefix
1 HEX: 0c <string> prefix ;
: etag-strings ( alist -- seq )
{ } swap [
[
[ first file>lines ]
[ second ] bi
[ etag ] with map
dup etag-length
] keep first
etag-header append
] each ;
: etags-write ( alist path -- )
[ etag-strings ] dip ascii set-file-lines ;
: etags ( path -- )
[ (ctags) sort-values etag-hash >alist ] dip etags-write ;

View File

@ -0,0 +1 @@
Etags generator