summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2016-01-30 14:16:36 +0200
committerEli Zaretskii <eliz@gnu.org>2016-01-30 14:16:36 +0200
commit25b79d7bc71079cd6ebb2700623e7e3b76b03287 (patch)
tree1654109110b07b8ebf8fd9b9196e73f2d4553972
parentccc3b3cd68312e1d69d9f9af943ee2b9a9d88198 (diff)
downloademacs-25b79d7bc71079cd6ebb2700623e7e3b76b03287.tar.gz
Improve Ruby support in 'etags'
* lib-src/etags.c (Ruby_functions): Tag constants. Don't tag singleton classes. Remove class qualifiers from tags generated for method and constant names. (Bug#22241) * doc/emacs/maintaining.texi (Tag Syntax): Mention that constants are tagged by etags in Ruby. * etc/NEWS: Mention that constants are tagged by etags in Ruby. * test/etags/ruby-src/test1.ruby: Add more tests. * test/etags/ETAGS.good_1: * test/etags/ETAGS.good_2: * test/etags/ETAGS.good_3: * test/etags/ETAGS.good_4: * test/etags/ETAGS.good_5: * test/etags/ETAGS.good_6: * test/etags/CTAGS.good: Adapt to the changes in etags and in Ruby tests.
-rw-r--r--doc/emacs/maintaining.texi2
-rw-r--r--etc/NEWS4
-rw-r--r--lib-src/etags.c58
-rw-r--r--test/etags/CTAGS.good11
-rw-r--r--test/etags/ETAGS.good_115
-rw-r--r--test/etags/ETAGS.good_215
-rw-r--r--test/etags/ETAGS.good_315
-rw-r--r--test/etags/ETAGS.good_415
-rw-r--r--test/etags/ETAGS.good_515
-rw-r--r--test/etags/ETAGS.good_615
-rw-r--r--test/etags/ruby-src/test1.ruby22
11 files changed, 154 insertions, 33 deletions
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 471a16b57de..7039de63e53 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -2264,7 +2264,7 @@ generate a tag.
@item
In Ruby code, @code{def} or @code{class} or @code{module} at the
-beginning of a line generate a tag.
+beginning of a line generate a tag. Constants also generate tags.
@end itemize
You can also generate tags based on regexp matching (@pxref{Etags
diff --git a/etc/NEWS b/etc/NEWS
index af2dee931f3..78dce166b43 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1830,8 +1830,8 @@ qualified names by hand.
+++
*** New language Ruby
-Names of modules, classes, methods, and functions are tagged.
-Overloaded operators are also tagged.
+Names of modules, classes, methods, functions, and constants are
+tagged. Overloaded operators are also tagged.
+++
*** Improved support for Lua
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 54ed1b428e9..adc08a23678 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -4550,18 +4550,68 @@ Ruby_functions (FILE *inf)
LOOP_ON_INPUT_LINES (inf, lb, cp)
{
+ bool is_class = false;
+ bool is_method = false;
+ char *name;
+
cp = skip_spaces (cp);
- if (LOOKING_AT (cp, "def")
- || LOOKING_AT (cp, "class")
- || LOOKING_AT (cp, "module"))
+ if (c_isalpha (*cp) && c_isupper (*cp)) /* constants */
{
- char *name = cp;
+ char *bp, *colon = NULL;
+
+ name = cp;
+
+ for (cp++; c_isalnum (*cp) || *cp == '_' || *cp == ':'; cp++)
+ {
+ if (*cp == ':')
+ colon = cp;
+ }
+ if (cp > name + 1)
+ {
+ bp = skip_spaces (cp);
+ if (*bp == '=' && c_isspace (bp[1]))
+ {
+ if (colon && !c_isspace (colon[1]))
+ name = colon + 1;
+ make_tag (name, cp - name, false,
+ lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
+ }
+ }
+ }
+ else if ((is_method = LOOKING_AT (cp, "def")) /* module/class/method */
+ || (is_class = LOOKING_AT (cp, "class"))
+ || LOOKING_AT (cp, "module"))
+ {
+ const char self_name[] = "self.";
+ const size_t self_size1 = sizeof ("self.") - 1;
+
+ name = cp;
/* Ruby method names can end in a '='. Also, operator overloading can
define operators whose names include '='. */
while (!notinname (*cp) || *cp == '=')
cp++;
+ /* Remove "self." from the method name. */
+ if (cp - name > self_size1
+ && strneq (name, self_name, self_size1))
+ name += self_size1;
+
+ /* Remove the class/module qualifiers from method names. */
+ if (is_method)
+ {
+ char *q;
+
+ for (q = name; q < cp && *q != '.'; q++)
+ ;
+ if (q < cp - 1) /* punt if we see just "FOO." */
+ name = q + 1;
+ }
+
+ /* Don't tag singleton classes. */
+ if (is_class && strneq (name, "<<", 2) && cp == name + 2)
+ continue;
+
make_tag (name, cp - name, true,
lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
}
diff --git a/test/etags/CTAGS.good b/test/etags/CTAGS.good
index 1c494d64277..86eb9f85cf3 100644
--- a/test/etags/CTAGS.good
+++ b/test/etags/CTAGS.good
@@ -227,6 +227,8 @@ A cp-src/c.C 117
A cp-src/fail.C 7
A cp-src/fail.C 23
A ruby-src/test1.ruby /^class A$/
+A ruby-src/test1.ruby /^module A$/
+ABC ruby-src/test1.ruby 11
ADDRESS c-src/emacs/src/gmalloc.c /^#define ADDRESS(B) ((void *) (((B) - 1) * BLOCKSIZ/
ALIGNOF_STRUCT_LISP_VECTOR c-src/emacs/src/lisp.h 1378
ALLOCATED_BEFORE_DUMPING c-src/emacs/src/gmalloc.c /^#define ALLOCATED_BEFORE_DUMPING(P) \\$/
@@ -289,6 +291,7 @@ B cp-src/c.C /^void B::B() {}$/
B cp-src/c.C 122
B cp-src/fail.C 8
B cp-src/fail.C 24
+B ruby-src/test1.ruby /^ class B$/
BE_Node cp-src/c.C /^void BE_Node::BE_Node() {}$/
BE_Node cp-src/c.C 77
BITS_PER_BITS_WORD c-src/emacs/src/lisp.h 125
@@ -438,7 +441,6 @@ Cjava_entries c-src/etags.c /^Cjava_entries (FILE *inf)$/
Cjava_help c-src/etags.c 551
Cjava_suffixes c-src/etags.c 549
ClassExample ruby-src/test.rb /^ class ClassExample$/
-ClassExample.class_method ruby-src/test.rb /^ def ClassExample.class_method$/
Clear/p ada-src/2ataspri.adb /^ procedure Clear (Cell : in out TAS_Cell) is$/
Clear/p ada-src/2ataspri.ads /^ procedure Clear (Cell : in out TAS_Cell)/
Cobol_help c-src/etags.c 558
@@ -458,6 +460,7 @@ Condition_Variable/t ada-src/2ataspri.ads /^ type Condition_Variable is privat
Condition_Variable/t ada-src/2ataspri.ads /^ type Condition_Variable is$/
Configure pyt-src/server.py /^class Configure(Frame, ControlEdit):$/
ConfirmQuit pyt-src/server.py /^def ConfirmQuit(frame, context):$/
+Constant ruby-src/test1.ruby 26
ControlEdit pyt-src/server.py /^class ControlEdit(Frame):$/
Controls pyt-src/server.py /^class Controls:$/
CopyTextString pas-src/common.pas /^function CopyTextString;(*($/
@@ -939,7 +942,6 @@ Metags c-src/etags.c /^main (int argc, char **argv)$/
Mfail cp-src/fail.C /^main()$/
Mkai-test.pl perl-src/kai-test.pl /^package main;$/
ModuleExample ruby-src/test.rb /^module ModuleExample$/
-ModuleExample.module_class_method ruby-src/test.rb /^ def ModuleExample.module_class_method$/
More_Lisp_Bits c-src/emacs/src/lisp.h 801
MoveLayerAfter lua-src/allegro.lua /^function MoveLayerAfter (this_one)$/
MoveLayerBefore lua-src/allegro.lua /^function MoveLayerBefore (this_one)$/
@@ -2351,6 +2353,7 @@ __str__ pyt-src/server.py /^ def __str__(self):$/
__up c.c 160
_aligned_blocks c-src/emacs/src/gmalloc.c 1004
_aligned_blocks_mutex c-src/emacs/src/gmalloc.c 518
+_bar? ruby-src/test1.ruby /^ def self._bar?(abc)$/
_bytes_free c-src/emacs/src/gmalloc.c 376
_bytes_used c-src/emacs/src/gmalloc.c 374
_chunks_free c-src/emacs/src/gmalloc.c 375
@@ -2620,6 +2623,7 @@ childDidExit objc-src/Subprocess.m /^- childDidExit$/
chunks_free c-src/emacs/src/gmalloc.c 313
chunks_used c-src/emacs/src/gmalloc.c 311
cjava c-src/etags.c 2936
+class_method ruby-src/test.rb /^ def ClassExample.class_method$/
classifyLine php-src/lce_functions.php /^ function classifyLine($line)$/
clear cp-src/conway.hpp /^ void clear(void) { alive = 0; }$/
clear-abbrev-table c-src/abbrev.c /^DEFUN ("clear-abbrev-table", Fclear_abbrev_table, /
@@ -2952,6 +2956,7 @@ foo f-src/entry.for /^ character*(*) function foo()$/
foo f-src/entry.strange_suffix /^ character*(*) function foo()$/
foo f-src/entry.strange /^ character*(*) function foo()$/
foo php-src/ptest.php /^foo()$/
+foo! ruby-src/test1.ruby /^ def foo!$/
foobar c-src/c.c /^int foobar() {;}$/
foobar c.c /^extern void foobar (void) __attribute__ ((section /
foobar2 c-src/h.h 20
@@ -3450,6 +3455,7 @@ miti html-src/softwarelibero.html /^Sfatiamo alcuni miti$/
modifier_names c-src/emacs/src/keyboard.c 6319
modifier_symbols c-src/emacs/src/keyboard.c 6327
modify_event_symbol c-src/emacs/src/keyboard.c /^modify_event_symbol (ptrdiff_t symbol_num, int mod/
+module_class_method ruby-src/test.rb /^ def ModuleExample.module_class_method$/
module_instance_method ruby-src/test.rb /^ def module_instance_method$/
more_aligned_int c.c 165
morecore_nolock c-src/emacs/src/gmalloc.c /^morecore_nolock (size_t size)$/
@@ -3812,6 +3818,7 @@ quantizing html-src/algrthms.html /^Quantizing the Received$/
questo ../c/c.web 34
quit_char c-src/emacs/src/keyboard.c 192
quit_throw_to_read_char c-src/emacs/src/keyboard.c /^quit_throw_to_read_char (bool from_signal)$/
+qux= ruby-src/test1.ruby /^ def qux=(tee)$/
r0 c-src/sysdep.h 54
r1 c-src/sysdep.h 55
r_alloc c-src/emacs/src/lisp.h /^extern void *r_alloc (void **, size_t) ATTRIBUTE_A/
diff --git a/test/etags/ETAGS.good_1 b/test/etags/ETAGS.good_1
index 52ded46e28a..44ac091066b 100644
--- a/test/etags/ETAGS.good_1
+++ b/test/etags/ETAGS.good_1
@@ -2977,11 +2977,11 @@ class Configure(760,24879
def save(797,26022
def nosave(807,26310
-ruby-src/test.rb,604
+ruby-src/test.rb,637
module ModuleExample1,0
class ClassExample2,21
def instance_method3,44
- def ClassExample.class_method6,121
+ def ClassExample.class_methodclass_method6,121
def instance_method_exclamation!9,206
def instance_method_question?12,310
def instance_method_equals=instance_method_equals=15,408
@@ -2995,12 +2995,19 @@ module ModuleExample1,0
def <=>(<=>39,943
def ===(===42,990
def module_instance_method46,1051
- def ModuleExample.module_class_method49,1131
+ def ModuleExample.module_class_methodmodule_class_method49,1131
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
class A1,0
def a(2,8
def b(5,38
+module A9,57
+ class B10,66
+ ABC 11,76
+ def foo!13,89
+ def self._bar?(_bar?16,111
+ def qux=(qux=20,162
+A::Constant Constant26,211
tex-src/testenv.tex,52
\newcommand{\nm}\nm4,77
diff --git a/test/etags/ETAGS.good_2 b/test/etags/ETAGS.good_2
index ea10012669c..8a93e3b0656 100644
--- a/test/etags/ETAGS.good_2
+++ b/test/etags/ETAGS.good_2
@@ -3548,11 +3548,11 @@ class Configure(760,24879
def save(797,26022
def nosave(807,26310
-ruby-src/test.rb,604
+ruby-src/test.rb,637
module ModuleExample1,0
class ClassExample2,21
def instance_method3,44
- def ClassExample.class_method6,121
+ def ClassExample.class_methodclass_method6,121
def instance_method_exclamation!9,206
def instance_method_question?12,310
def instance_method_equals=instance_method_equals=15,408
@@ -3566,12 +3566,19 @@ module ModuleExample1,0
def <=>(<=>39,943
def ===(===42,990
def module_instance_method46,1051
- def ModuleExample.module_class_method49,1131
+ def ModuleExample.module_class_methodmodule_class_method49,1131
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
class A1,0
def a(2,8
def b(5,38
+module A9,57
+ class B10,66
+ ABC 11,76
+ def foo!13,89
+ def self._bar?(_bar?16,111
+ def qux=(qux=20,162
+A::Constant Constant26,211
tex-src/testenv.tex,52
\newcommand{\nm}\nm4,77
diff --git a/test/etags/ETAGS.good_3 b/test/etags/ETAGS.good_3
index 3b3650f8fa8..e575b40ab0d 100644
--- a/test/etags/ETAGS.good_3
+++ b/test/etags/ETAGS.good_3
@@ -3321,11 +3321,11 @@ class Configure(760,24879
def save(797,26022
def nosave(807,26310
-ruby-src/test.rb,604
+ruby-src/test.rb,637
module ModuleExample1,0
class ClassExample2,21
def instance_method3,44
- def ClassExample.class_method6,121
+ def ClassExample.class_methodclass_method6,121
def instance_method_exclamation!9,206
def instance_method_question?12,310
def instance_method_equals=instance_method_equals=15,408
@@ -3339,12 +3339,19 @@ module ModuleExample1,0
def <=>(<=>39,943
def ===(===42,990
def module_instance_method46,1051
- def ModuleExample.module_class_method49,1131
+ def ModuleExample.module_class_methodmodule_class_method49,1131
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
class A1,0
def a(2,8
def b(5,38
+module A9,57
+ class B10,66
+ ABC 11,76
+ def foo!13,89
+ def self._bar?(_bar?16,111
+ def qux=(qux=20,162
+A::Constant Constant26,211
tex-src/testenv.tex,52
\newcommand{\nm}\nm4,77
diff --git a/test/etags/ETAGS.good_4 b/test/etags/ETAGS.good_4
index 0415c17bff3..28258060517 100644
--- a/test/etags/ETAGS.good_4
+++ b/test/etags/ETAGS.good_4
@@ -3141,11 +3141,11 @@ class Configure(760,24879
def save(797,26022
def nosave(807,26310
-ruby-src/test.rb,604
+ruby-src/test.rb,637
module ModuleExample1,0
class ClassExample2,21
def instance_method3,44
- def ClassExample.class_method6,121
+ def ClassExample.class_methodclass_method6,121
def instance_method_exclamation!9,206
def instance_method_question?12,310
def instance_method_equals=instance_method_equals=15,408
@@ -3159,12 +3159,19 @@ module ModuleExample1,0
def <=>(<=>39,943
def ===(===42,990
def module_instance_method46,1051
- def ModuleExample.module_class_method49,1131
+ def ModuleExample.module_class_methodmodule_class_method49,1131
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
class A1,0
def a(2,8
def b(5,38
+module A9,57
+ class B10,66
+ ABC 11,76
+ def foo!13,89
+ def self._bar?(_bar?16,111
+ def qux=(qux=20,162
+A::Constant Constant26,211
tex-src/testenv.tex,52
\newcommand{\nm}\nm4,77
diff --git a/test/etags/ETAGS.good_5 b/test/etags/ETAGS.good_5
index 8dc814e5ac8..35bb353c767 100644
--- a/test/etags/ETAGS.good_5
+++ b/test/etags/ETAGS.good_5
@@ -4056,11 +4056,11 @@ class Configure(760,24879
def save(797,26022
def nosave(807,26310
-ruby-src/test.rb,604
+ruby-src/test.rb,637
module ModuleExample1,0
class ClassExample2,21
def instance_method3,44
- def ClassExample.class_method6,121
+ def ClassExample.class_methodclass_method6,121
def instance_method_exclamation!9,206
def instance_method_question?12,310
def instance_method_equals=instance_method_equals=15,408
@@ -4074,12 +4074,19 @@ module ModuleExample1,0
def <=>(<=>39,943
def ===(===42,990
def module_instance_method46,1051
- def ModuleExample.module_class_method49,1131
+ def ModuleExample.module_class_methodmodule_class_method49,1131
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
class A1,0
def a(2,8
def b(5,38
+module A9,57
+ class B10,66
+ ABC 11,76
+ def foo!13,89
+ def self._bar?(_bar?16,111
+ def qux=(qux=20,162
+A::Constant Constant26,211
tex-src/testenv.tex,52
\newcommand{\nm}\nm4,77
diff --git a/test/etags/ETAGS.good_6 b/test/etags/ETAGS.good_6
index 322c1651984..8add300784f 100644
--- a/test/etags/ETAGS.good_6
+++ b/test/etags/ETAGS.good_6
@@ -4056,11 +4056,11 @@ class Configure(760,24879
def save(797,26022
def nosave(807,26310
-ruby-src/test.rb,604
+ruby-src/test.rb,637
module ModuleExample1,0
class ClassExample2,21
def instance_method3,44
- def ClassExample.class_method6,121
+ def ClassExample.class_methodclass_method6,121
def instance_method_exclamation!9,206
def instance_method_question?12,310
def instance_method_equals=instance_method_equals=15,408
@@ -4074,12 +4074,19 @@ module ModuleExample1,0
def <=>(<=>39,943
def ===(===42,990
def module_instance_method46,1051
- def ModuleExample.module_class_method49,1131
+ def ModuleExample.module_class_methodmodule_class_method49,1131
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
class A1,0
def a(2,8
def b(5,38
+module A9,57
+ class B10,66
+ ABC 11,76
+ def foo!13,89
+ def self._bar?(_bar?16,111
+ def qux=(qux=20,162
+A::Constant Constant26,211
tex-src/testenv.tex,52
\newcommand{\nm}\nm4,77
diff --git a/test/etags/ruby-src/test1.ruby b/test/etags/ruby-src/test1.ruby
index 43b1a14b95e..26b7d538b64 100644
--- a/test/etags/ruby-src/test1.ruby
+++ b/test/etags/ruby-src/test1.ruby
@@ -5,3 +5,25 @@ class A
def b()
end
end
+
+module A
+ class B
+ ABC = 4
+
+ def foo!
+ end
+
+ def self._bar?(abc)
+ end
+
+ class << self
+ def qux=(tee)
+ end
+ end
+ end
+end
+
+A::Constant = 5
+
+# def foo_in_comment
+# end