From 222aa829bcdf6ad0520254574f395d787416cf3d Mon Sep 17 00:00:00 2001 From: Alfredo Beaumont Date: Sun, 13 Jul 2008 18:35:44 +0200 Subject: [PATCH] Add authors and summary and documentation files and polish testsuite --- extra/ctags/etags/authors.txt | 1 + extra/ctags/etags/etags-docs.factor | 39 +++++++++++ extra/ctags/etags/etags-tests.factor | 101 +++++++++++++++++---------- extra/ctags/etags/etags.factor | 6 +- extra/ctags/etags/summary.txt | 1 + 5 files changed, 107 insertions(+), 41 deletions(-) create mode 100644 extra/ctags/etags/authors.txt create mode 100644 extra/ctags/etags/etags-docs.factor create mode 100644 extra/ctags/etags/summary.txt diff --git a/extra/ctags/etags/authors.txt b/extra/ctags/etags/authors.txt new file mode 100644 index 0000000000..158cf94ea0 --- /dev/null +++ b/extra/ctags/etags/authors.txt @@ -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 index 0000000000..c38404740a --- /dev/null +++ b/extra/ctags/etags/etags-docs.factor @@ -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 index 8d5fc0ee02..6ab97e0566 100644 --- a/extra/ctags/etags/etags-tests.factor +++ b/extra/ctags/etags/etags-tests.factor @@ -1,47 +1,72 @@ USING: kernel ctags ctags.etags tools.test io.backend sequences arrays prettyprint hashtables assocs ; IN: ctags.etags.tests - -[ H{ { "path" V{ if { "path" 1 } } } } ] -[ H{ } clone dup V{ if { "path" 1 } } "path" rot set-at ] unit-test - -[ { "path" V{ if { "path" 1 } } } ] -[ H{ } clone dup { "path" V{ if { "path" 1 } } } "path" rot set-at "path" swap at ] unit-test - - -[ V{ if { "path" 1 } } ] -[ "path" H{ { "path" V{ if { "path" 1 } } } } at ] unit-test - -[ "path" ] [ { if { "path" 1 } } ctag-path ] unit-test - -[ V{ } ] -[ "path" H{ } clone etag-at ] unit-test - -[ V{ if { "path" 1 } } ] -[ "path" H{ { "path" V{ if { "path" 1 } } } } etag-at ] unit-test - -[ { if 28 } ] -[ { if { "resource:core/kernel/kernel.factor" 28 } } etag-pair ] 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 - etag-vector +! etag-at +[ t ] +[ + V{ } + "path" H{ } clone etag-at = ] unit-test -[ H{ { "path" V{ { if 1 } } } } ] -[ { if { "path" 1 } } H{ } clone [ etag-add ] keep ] unit-test +[ t ] +[ + V{ if { "path" 1 } } + "path" H{ { "path" V{ if { "path" 1 } } } } etag-at = +] unit-test -[ H{ { "path" V{ { if 1 } } } } ] -[ { { if { "path" 1 } } } etag-hash ] unit-test +! etag-vector +[ t ] +[ + V{ } + { if { "path" 1 } } H{ } clone etag-vector = +] unit-test -[ "if28,704" ] -[ "resource:core/kernel/kernel.factor" file>lines { if 28 } etag ] unit-test +[ t ] +[ + V{ if { "path" 1 } } + { if { "path" 1 } } + { { "path" V{ if { "path" 1 } } } } >hashtable + etag-vector = +] unit-test -! [ V{ " " "resource:core/kernel/kernel.factor,22" "if28,704" "unless31,755" } ] -! [ { { "resource:core/kernel/kernel.factor" -! V{ { if 28 } -! { unless 31 } } } } etag-strings ] 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 diff --git a/extra/ctags/etags/etags.factor b/extra/ctags/etags/etags.factor index b3ad879481..8cc8c284b1 100644 --- a/extra/ctags/etags/etags.factor +++ b/extra/ctags/etags/etags.factor @@ -31,7 +31,7 @@ IN: ctags.etags : lines>bytes ( seq n -- bytes ) head 0 [ length 1+ + ] reduce ; -: file>lines ( resource -- lines ) +: file>lines ( path -- lines ) ascii file-lines ; : etag ( lines seq -- str ) @@ -46,7 +46,7 @@ IN: ctags.etags : etag-length ( vector -- n ) 0 [ length + ] reduce ; -:
( n path -- str ) +: (etag-header) ( n path -- str ) [ % 1 CHAR: , % @@ -54,7 +54,7 @@ IN: ctags.etags ] "" make ; : etag-header ( vec1 n resource -- vec2 ) - normalize-path
prefix + normalize-path (etag-header) prefix 1 HEX: 0c prefix ; : etag-strings ( alist -- seq ) diff --git a/extra/ctags/etags/summary.txt b/extra/ctags/etags/summary.txt new file mode 100644 index 0000000000..4766e20a87 --- /dev/null +++ b/extra/ctags/etags/summary.txt @@ -0,0 +1 @@ +Etags generator