]> code.delx.au - gnu-emacs/commitdiff
Improve Ruby support in 'etags'
authorEli Zaretskii <eliz@gnu.org>
Sat, 30 Jan 2016 12:16:36 +0000 (14:16 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 30 Jan 2016 12:16:36 +0000 (14:16 +0200)
* 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.

doc/emacs/maintaining.texi
etc/NEWS
lib-src/etags.c
test/etags/CTAGS.good
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/ruby-src/test1.ruby

index 471a16b57de63593e2b8f78a0083e4969c9d9edc..7039de63e538a9790105181e7a94adfa474b792a 100644 (file)
@@ -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
index af2dee931f3a4deeb881ca63ad31431f729c7aa6..78dce166b43c0644464f9fbe9b808be255f69275 100644 (file)
--- 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
index 54ed1b428e9b9d5b860570f3bf85314f88e431bc..adc08a2367817967532dc3244d1716ff3bb228c8 100644 (file)
@@ -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);
        }
index 1c494d6427731956fc86c6948780228f7be179a6..86eb9f85cf3180e352f90d0b63b55bc651e46a5b 100644 (file)
@@ -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/
index 52ded46e28adc5bb110e41d45081b0be060ced9c..44ac091066b0a1a9c8eb1db51398dd39fb3841ed 100644 (file)
@@ -2977,11 +2977,11 @@ class Configure(\7f760,24879
     def save(\7f797,26022
     def nosave(\7f807,26310
 \f
-ruby-src/test.rb,604
+ruby-src/test.rb,637
 module ModuleExample\7f1,0
     class ClassExample\7f2,21
         def instance_method\7f3,44
-        def ClassExample.class_method\7f6,121
+        def ClassExample.class_method\7fclass_method\ 16,121
         def instance_method_exclamation!\7f9,206
         def instance_method_question?\7f12,310
         def instance_method_equals=\7finstance_method_equals=\ 115,408
@@ -2995,12 +2995,19 @@ module ModuleExample\7f1,0
         def <=>(\7f<=>\ 139,943
         def ===(\7f===\ 142,990
     def module_instance_method\7f46,1051
-    def ModuleExample.module_class_method\7f49,1131
+    def ModuleExample.module_class_method\7fmodule_class_method\ 149,1131
 \f
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
 class A\7f1,0
  def a(\7f2,8
  def b(\7f5,38
+module A\7f9,57
+  class B\7f10,66
+    ABC \7f11,76
+    def foo!\7f13,89
+    def self._bar?(\7f_bar?\ 116,111
+      def qux=(\7fqux=\ 120,162
+A::Constant \7fConstant\ 126,211
 \f
 tex-src/testenv.tex,52
 \newcommand{\nm}\7f\nm\ 14,77
index ea10012669cfe1bd65f2145f680f6937636d8d85..8a93e3b0656f3db4b393e0108b44117fa273cc74 100644 (file)
@@ -3548,11 +3548,11 @@ class Configure(\7f760,24879
     def save(\7f797,26022
     def nosave(\7f807,26310
 \f
-ruby-src/test.rb,604
+ruby-src/test.rb,637
 module ModuleExample\7f1,0
     class ClassExample\7f2,21
         def instance_method\7f3,44
-        def ClassExample.class_method\7f6,121
+        def ClassExample.class_method\7fclass_method\ 16,121
         def instance_method_exclamation!\7f9,206
         def instance_method_question?\7f12,310
         def instance_method_equals=\7finstance_method_equals=\ 115,408
@@ -3566,12 +3566,19 @@ module ModuleExample\7f1,0
         def <=>(\7f<=>\ 139,943
         def ===(\7f===\ 142,990
     def module_instance_method\7f46,1051
-    def ModuleExample.module_class_method\7f49,1131
+    def ModuleExample.module_class_method\7fmodule_class_method\ 149,1131
 \f
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
 class A\7f1,0
  def a(\7f2,8
  def b(\7f5,38
+module A\7f9,57
+  class B\7f10,66
+    ABC \7f11,76
+    def foo!\7f13,89
+    def self._bar?(\7f_bar?\ 116,111
+      def qux=(\7fqux=\ 120,162
+A::Constant \7fConstant\ 126,211
 \f
 tex-src/testenv.tex,52
 \newcommand{\nm}\7f\nm\ 14,77
index 3b3650f8fa820913860f8dda3c7af84e80099f64..e575b40ab0d981dfad9fc2c06312c1e699f0707c 100644 (file)
@@ -3321,11 +3321,11 @@ class Configure(\7f760,24879
     def save(\7f797,26022
     def nosave(\7f807,26310
 \f
-ruby-src/test.rb,604
+ruby-src/test.rb,637
 module ModuleExample\7f1,0
     class ClassExample\7f2,21
         def instance_method\7f3,44
-        def ClassExample.class_method\7f6,121
+        def ClassExample.class_method\7fclass_method\ 16,121
         def instance_method_exclamation!\7f9,206
         def instance_method_question?\7f12,310
         def instance_method_equals=\7finstance_method_equals=\ 115,408
@@ -3339,12 +3339,19 @@ module ModuleExample\7f1,0
         def <=>(\7f<=>\ 139,943
         def ===(\7f===\ 142,990
     def module_instance_method\7f46,1051
-    def ModuleExample.module_class_method\7f49,1131
+    def ModuleExample.module_class_method\7fmodule_class_method\ 149,1131
 \f
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
 class A\7f1,0
  def a(\7f2,8
  def b(\7f5,38
+module A\7f9,57
+  class B\7f10,66
+    ABC \7f11,76
+    def foo!\7f13,89
+    def self._bar?(\7f_bar?\ 116,111
+      def qux=(\7fqux=\ 120,162
+A::Constant \7fConstant\ 126,211
 \f
 tex-src/testenv.tex,52
 \newcommand{\nm}\7f\nm\ 14,77
index 0415c17bff305e6a4907ae62723d2193920950d4..282580605179ac12b60a99fb57047930ce070d54 100644 (file)
@@ -3141,11 +3141,11 @@ class Configure(\7f760,24879
     def save(\7f797,26022
     def nosave(\7f807,26310
 \f
-ruby-src/test.rb,604
+ruby-src/test.rb,637
 module ModuleExample\7f1,0
     class ClassExample\7f2,21
         def instance_method\7f3,44
-        def ClassExample.class_method\7f6,121
+        def ClassExample.class_method\7fclass_method\ 16,121
         def instance_method_exclamation!\7f9,206
         def instance_method_question?\7f12,310
         def instance_method_equals=\7finstance_method_equals=\ 115,408
@@ -3159,12 +3159,19 @@ module ModuleExample\7f1,0
         def <=>(\7f<=>\ 139,943
         def ===(\7f===\ 142,990
     def module_instance_method\7f46,1051
-    def ModuleExample.module_class_method\7f49,1131
+    def ModuleExample.module_class_method\7fmodule_class_method\ 149,1131
 \f
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
 class A\7f1,0
  def a(\7f2,8
  def b(\7f5,38
+module A\7f9,57
+  class B\7f10,66
+    ABC \7f11,76
+    def foo!\7f13,89
+    def self._bar?(\7f_bar?\ 116,111
+      def qux=(\7fqux=\ 120,162
+A::Constant \7fConstant\ 126,211
 \f
 tex-src/testenv.tex,52
 \newcommand{\nm}\7f\nm\ 14,77
index 8dc814e5ac8707fb5eb169523dc86e17f53e228d..35bb353c7671a37f213723e0f045f79071b992a2 100644 (file)
@@ -4056,11 +4056,11 @@ class Configure(\7f760,24879
     def save(\7f797,26022
     def nosave(\7f807,26310
 \f
-ruby-src/test.rb,604
+ruby-src/test.rb,637
 module ModuleExample\7f1,0
     class ClassExample\7f2,21
         def instance_method\7f3,44
-        def ClassExample.class_method\7f6,121
+        def ClassExample.class_method\7fclass_method\ 16,121
         def instance_method_exclamation!\7f9,206
         def instance_method_question?\7f12,310
         def instance_method_equals=\7finstance_method_equals=\ 115,408
@@ -4074,12 +4074,19 @@ module ModuleExample\7f1,0
         def <=>(\7f<=>\ 139,943
         def ===(\7f===\ 142,990
     def module_instance_method\7f46,1051
-    def ModuleExample.module_class_method\7f49,1131
+    def ModuleExample.module_class_method\7fmodule_class_method\ 149,1131
 \f
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
 class A\7f1,0
  def a(\7f2,8
  def b(\7f5,38
+module A\7f9,57
+  class B\7f10,66
+    ABC \7f11,76
+    def foo!\7f13,89
+    def self._bar?(\7f_bar?\ 116,111
+      def qux=(\7fqux=\ 120,162
+A::Constant \7fConstant\ 126,211
 \f
 tex-src/testenv.tex,52
 \newcommand{\nm}\7f\nm\ 14,77
index 322c1651984f6516d8c327944de9e8338fbb474e..8add300784fb8b90ec68c261157a5f69db2fe836 100644 (file)
@@ -4056,11 +4056,11 @@ class Configure(\7f760,24879
     def save(\7f797,26022
     def nosave(\7f807,26310
 \f
-ruby-src/test.rb,604
+ruby-src/test.rb,637
 module ModuleExample\7f1,0
     class ClassExample\7f2,21
         def instance_method\7f3,44
-        def ClassExample.class_method\7f6,121
+        def ClassExample.class_method\7fclass_method\ 16,121
         def instance_method_exclamation!\7f9,206
         def instance_method_question?\7f12,310
         def instance_method_equals=\7finstance_method_equals=\ 115,408
@@ -4074,12 +4074,19 @@ module ModuleExample\7f1,0
         def <=>(\7f<=>\ 139,943
         def ===(\7f===\ 142,990
     def module_instance_method\7f46,1051
-    def ModuleExample.module_class_method\7f49,1131
+    def ModuleExample.module_class_method\7fmodule_class_method\ 149,1131
 \f
-ruby-src/test1.ruby,37
+ruby-src/test1.ruby,191
 class A\7f1,0
  def a(\7f2,8
  def b(\7f5,38
+module A\7f9,57
+  class B\7f10,66
+    ABC \7f11,76
+    def foo!\7f13,89
+    def self._bar?(\7f_bar?\ 116,111
+      def qux=(\7fqux=\ 120,162
+A::Constant \7fConstant\ 126,211
 \f
 tex-src/testenv.tex,52
 \newcommand{\nm}\7f\nm\ 14,77
index 43b1a14b95eb626c24ab4942d3e6f1a1e9df72a4..26b7d538b641022b6ebd77dc9fb39571928df1d5 100644 (file)
@@ -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