aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorDavid Hull2019-06-25 19:12:22 +0200
committerLars Ingebrigtsen2019-06-25 19:14:20 +0200
commitf0151e17d296bfdeb1ca3f002c9b430c8302a6e7 (patch)
treea3b1d497fb7f353b70dd78ae3fee027b2452b9e6 /lib-src
parenta8457f0adadacbb0360d84b0ed6d59a34c56d58c (diff)
downloademacs-f0151e17d296bfdeb1ca3f002c9b430c8302a6e7.tar.gz
emacs-f0151e17d296bfdeb1ca3f002c9b430c8302a6e7.zip
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).
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index f70a1f67bc8..442b622cceb 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -6043,7 +6043,7 @@ prolog_atom (char *s, size_t pos)
6043 * Assumes that Erlang functions start at column 0. 6043 * Assumes that Erlang functions start at column 0.
6044 * Original code by Anders Lindgren (1996) 6044 * Original code by Anders Lindgren (1996)
6045 */ 6045 */
6046static int erlang_func (char *, char *); 6046static int erlang_func (char *, char *, int *);
6047static void erlang_attribute (char *); 6047static void erlang_attribute (char *);
6048static int erlang_atom (char *); 6048static int erlang_atom (char *);
6049 6049
@@ -6053,6 +6053,7 @@ Erlang_functions (FILE *inf)
6053 char *cp, *last; 6053 char *cp, *last;
6054 int len; 6054 int len;
6055 int allocated; 6055 int allocated;
6056 int name_offset = 0;
6056 6057
6057 allocated = 0; 6058 allocated = 0;
6058 len = 0; 6059 len = 0;
@@ -6077,7 +6078,7 @@ Erlang_functions (FILE *inf)
6077 last = NULL; 6078 last = NULL;
6078 } 6079 }
6079 } 6080 }
6080 else if ((len = erlang_func (cp, last)) > 0) 6081 else if ((len = erlang_func (cp, last, &name_offset)) > 0)
6081 { 6082 {
6082 /* 6083 /*
6083 * Function. Store the function name so that we only 6084 * Function. Store the function name so that we only
@@ -6088,7 +6089,7 @@ Erlang_functions (FILE *inf)
6088 else if (len + 1 > allocated) 6089 else if (len + 1 > allocated)
6089 xrnew (last, len + 1, char); 6090 xrnew (last, len + 1, char);
6090 allocated = len + 1; 6091 allocated = len + 1;
6091 memcpy (last, cp, len); 6092 memcpy (last, cp + name_offset, len);
6092 last[len] = '\0'; 6093 last[len] = '\0';
6093 } 6094 }
6094 } 6095 }
@@ -6107,12 +6108,13 @@ Erlang_functions (FILE *inf)
6107 * was found. 6108 * was found.
6108 */ 6109 */
6109static int 6110static int
6110erlang_func (char *s, char *last) 6111erlang_func (char *s, char *last, int *name_offset)
6111 6112
6112 /* Name of last clause. */ 6113 /* Name of last clause. */
6113{ 6114{
6114 int pos; 6115 int pos;
6115 int len; 6116 int len;
6117 char *name = s;
6116 6118
6117 pos = erlang_atom (s); 6119 pos = erlang_atom (s);
6118 if (pos < 1) 6120 if (pos < 1)
@@ -6121,13 +6123,23 @@ erlang_func (char *s, char *last)
6121 len = pos; 6123 len = pos;
6122 pos = skip_spaces (s + pos) - s; 6124 pos = skip_spaces (s + pos) - s;
6123 6125
6126 /* If the name is quoted, the quotes are not part of the name. */
6127 if (len > 2 && name[0] == '\'' && name[len - 1] == '\'')
6128 {
6129 *name_offset = 1;
6130 name++;
6131 len -= 2;
6132 }
6133 else
6134 *name_offset = 0;
6135
6124 /* Save only the first clause. */ 6136 /* Save only the first clause. */
6125 if (s[pos++] == '(' 6137 if (s[pos++] == '('
6126 && (last == NULL 6138 && (last == NULL
6127 || len != (int)strlen (last) 6139 || len != (int)strlen (last)
6128 || !strneq (s, last, len))) 6140 || !strneq (name, last, len)))
6129 { 6141 {
6130 make_tag (s, len, true, s, pos, lineno, linecharno); 6142 make_tag (name, len, true, s, pos, lineno, linecharno);
6131 return len; 6143 return len;
6132 } 6144 }
6133 6145
@@ -6148,13 +6160,25 @@ static void
6148erlang_attribute (char *s) 6160erlang_attribute (char *s)
6149{ 6161{
6150 char *cp = s; 6162 char *cp = s;
6163 int pos;
6164 int len;
6151 6165
6152 if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record")) 6166 if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record"))
6153 && *cp++ == '(') 6167 && *cp++ == '(')
6154 { 6168 {
6155 int len = erlang_atom (skip_spaces (cp)); 6169 cp = skip_spaces (cp);
6170 len = erlang_atom (cp);
6171 pos = cp + len - s;
6156 if (len > 0) 6172 if (len > 0)
6157 make_tag (cp, len, true, s, cp + len - s, lineno, linecharno); 6173 {
6174 /* If the name is quoted, the quotes are not part of the name. */
6175 if (len > 2 && cp[0] == '\'' && cp[len - 1] == '\'')
6176 {
6177 cp++;
6178 len -= 2;
6179 }
6180 make_tag (cp, len, true, s, pos, lineno, linecharno);
6181 }
6158 } 6182 }
6159 return; 6183 return;
6160} 6184}