]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of http://alfredobeaumont.org/factor
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 14 Jul 2008 05:50:29 +0000 (00:50 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 14 Jul 2008 05:50:29 +0000 (00:50 -0500)
extra/ctags/ctags-docs.factor
extra/ctags/ctags-tests.factor
extra/ctags/ctags.factor
extra/ctags/etags/authors.txt [new file with mode: 0644]
extra/ctags/etags/etags-docs.factor [new file with mode: 0644]
extra/ctags/etags/etags-tests.factor [new file with mode: 0644]
extra/ctags/etags/etags.factor [new file with mode: 0644]
extra/ctags/etags/summary.txt [new file with mode: 0644]

index 22d811ad3fda0cbba02f9b4a54c7c4cbdde81a73..32f3e05c6e41ab4a20428082146b740b64112bf8 100644 (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"
\ No newline at end of file
index 6c73b58ecb7837a59cf60d2728a19ab5a28b5c6a..700b8976570ab85bb46aacba5151c8ced80e52c8 100644 (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
\ No newline at end of file
+] unit-test
+
index 23d9aeb90cdca789874ae50f01684294fd7862d9..e8c5608375cb9e569658ce1c5f64399a429c3513 100644 (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 ;
\ No newline at end of file
diff --git a/extra/ctags/etags/authors.txt b/extra/ctags/etags/authors.txt
new file mode 100644 (file)
index 0000000..158cf94
--- /dev/null
@@ -0,0 +1 @@
+Alfredo Beaumont
diff --git a/extra/ctags/etags/etags-docs.factor b/extra/ctags/etags/etags-docs.factor
new file mode 100644 (file)
index 0000000..5bd4e10
--- /dev/null
@@ -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" ;
\ No newline at end of file
diff --git a/extra/ctags/etags/etags-tests.factor b/extra/ctags/etags/etags-tests.factor
new file mode 100644 (file)
index 0000000..6ab97e0
--- /dev/null
@@ -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 ]
+[
+  "if\7f2,11"
+  { "1234567890" "12345" } { if 2 } etag =
+] unit-test
+
+! etag-length
+[ t ]
+[
+  14
+  V{ "if\7f2,11" "if\7f2,11" } etag-length =
+] unit-test
diff --git a/extra/ctags/etags/etags.factor b/extra/ctags/etags/etags.factor
new file mode 100644 (file)
index 0000000..8cc8c28
--- /dev/null
@@ -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 ;
\ No newline at end of file
diff --git a/extra/ctags/etags/summary.txt b/extra/ctags/etags/summary.txt
new file mode 100644 (file)
index 0000000..4766e20
--- /dev/null
@@ -0,0 +1 @@
+Etags generator