emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master f0151e1: etags: Fix handling of quoted symbol names


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master f0151e1: etags: Fix handling of quoted symbol names in Erlang
Date: Tue, 25 Jun 2019 13:14:25 -0400 (EDT)

branch: master
commit f0151e17d296bfdeb1ca3f002c9b430c8302a6e7
Author: David Hull <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    etags: Fix handling of quoted symbol names in Erlang
    
    * lib-src/etags.c (erlang_attribute): Fix handling of quoted
    symbol names in Erlang (bug#24960).
---
 lib-src/etags.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/lib-src/etags.c b/lib-src/etags.c
index f70a1f6..442b622 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -6043,7 +6043,7 @@ prolog_atom (char *s, size_t pos)
  * Assumes that Erlang functions start at column 0.
  * Original code by Anders Lindgren (1996)
  */
-static int erlang_func (char *, char *);
+static int erlang_func (char *, char *, int *);
 static void erlang_attribute (char *);
 static int erlang_atom (char *);
 
@@ -6053,6 +6053,7 @@ Erlang_functions (FILE *inf)
   char *cp, *last;
   int len;
   int allocated;
+  int name_offset = 0;
 
   allocated = 0;
   len = 0;
@@ -6077,7 +6078,7 @@ Erlang_functions (FILE *inf)
              last = NULL;
            }
        }
-      else if ((len = erlang_func (cp, last)) > 0)
+      else if ((len = erlang_func (cp, last, &name_offset)) > 0)
        {
          /*
           * Function.  Store the function name so that we only
@@ -6088,7 +6089,7 @@ Erlang_functions (FILE *inf)
          else if (len + 1 > allocated)
            xrnew (last, len + 1, char);
          allocated = len + 1;
-         memcpy (last, cp, len);
+         memcpy (last, cp + name_offset, len);
          last[len] = '\0';
        }
     }
@@ -6107,12 +6108,13 @@ Erlang_functions (FILE *inf)
  * was found.
  */
 static int
-erlang_func (char *s, char *last)
+erlang_func (char *s, char *last, int *name_offset)
 
                                /* Name of last clause. */
 {
   int pos;
   int len;
+  char *name = s;
 
   pos = erlang_atom (s);
   if (pos < 1)
@@ -6121,13 +6123,23 @@ erlang_func (char *s, char *last)
   len = pos;
   pos = skip_spaces (s + pos) - s;
 
+  /* If the name is quoted, the quotes are not part of the name. */
+  if (len > 2 && name[0] == '\'' && name[len - 1] == '\'')
+    {
+      *name_offset = 1;
+      name++;
+      len -= 2;
+    }
+  else
+    *name_offset = 0;
+
   /* Save only the first clause. */
   if (s[pos++] == '('
       && (last == NULL
          || len != (int)strlen (last)
-         || !strneq (s, last, len)))
+         || !strneq (name, last, len)))
        {
-         make_tag (s, len, true, s, pos, lineno, linecharno);
+         make_tag (name, len, true, s, pos, lineno, linecharno);
          return len;
        }
 
@@ -6148,13 +6160,25 @@ static void
 erlang_attribute (char *s)
 {
   char *cp = s;
+  int pos;
+  int len;
 
   if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record"))
       && *cp++ == '(')
     {
-      int len = erlang_atom (skip_spaces (cp));
+      cp = skip_spaces (cp);
+      len = erlang_atom (cp);
+      pos = cp + len - s;
       if (len > 0)
-       make_tag (cp, len, true, s, cp + len - s, lineno, linecharno);
+       {
+         /* If the name is quoted, the quotes are not part of the name. */
+         if (len > 2 && cp[0] == '\'' && cp[len - 1] == '\'')
+           {
+             cp++;
+             len -= 2;
+           }
+         make_tag (cp, len, true, s, pos, lineno, linecharno);
+       }
     }
   return;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]