4 * Copyright (c) 2000-2003, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * Thanks are due to Jay Glanville for significant improvements.
11 * This module contains functions for generating tags for user-defined
12 * functions for the Vim editor.
18 #include "general.h" /* must always come first */
35 static kindOption VimKinds
[] = {
36 { TRUE
, 'a', "augroup", "autocommand groups" },
37 { TRUE
, 'f', "function", "function definitions" },
38 { TRUE
, 'v', "variable", "variable definitions" },
42 * FUNCTION DEFINITIONS
45 /* This function takes a char pointer, tries to find a scope separator in the
46 * string, and if it does, returns a pointer to the character after the colon,
47 * and the character defining the scope.
48 * If a colon is not found, it returns the original pointer.
50 static const unsigned char* skipPrefix (const unsigned char* name
, int *scope
)
52 const unsigned char* result
= name
;
61 else if (strncasecmp ((const char*) name
, "<SID>", (size_t) 5) == 0)
70 static void findVimTags (void)
72 vString
*name
= vStringNew ();
73 const unsigned char *line
;
74 boolean inFunction
= FALSE
;
77 while ((line
= fileReadLine ()) != NULL
)
79 while (isspace ((int) *line
))
81 if ((int) *line
== '"')
82 continue; /* skip comment */
83 if (strncmp ((const char*) line
, "fu", (size_t) 2) == 0)
85 const unsigned char *cp
= line
+ 1;
88 if ((int) *++cp
== 'n' && (int) *++cp
== 'c' &&
89 (int) *++cp
== 't' && (int) *++cp
== 'i' &&
90 (int) *++cp
== 'o' && (int) *++cp
== 'n')
94 if (isspace ((int) *cp
))
96 while (isspace ((int) *cp
))
98 cp
= skipPrefix (cp
, &scope
);
99 if (isupper ((int) *cp
) || scope
== 's' || scope
== '<')
103 vStringPut (name
, (int) *cp
);
105 } while (isalnum ((int) *cp
) || *cp
== '_');
106 vStringTerminate (name
);
107 makeSimpleTag (name
, VimKinds
, K_FUNCTION
);
113 if (strncmp ((const char*) line
, "aug", (size_t) 3) == 0)
115 /* Found Autocommand Group (augroup) */
116 const unsigned char *cp
= line
+ 2;
117 if ((int) *++cp
== 'r' && (int) *++cp
== 'o' &&
118 (int) *++cp
== 'u' && (int) *++cp
== 'p')
120 if (isspace ((int) *cp
))
122 while (isspace ((int) *cp
))
124 if (strncasecmp ((const char*) cp
, "end", (size_t) 3) != 0)
128 vStringPut (name
, (int) *cp
);
130 } while (isalnum ((int) *cp
) || *cp
== '_');
131 vStringTerminate (name
);
132 makeSimpleTag (name
, VimKinds
, K_AUGROUP
);
138 if (strncmp ((const char*) line
, "endf", (size_t) 4) == 0)
142 strncmp ((const char*) line
, "let", (size_t) 3) == 0)
144 /* we've found a variable declared outside of a function!! */
145 const unsigned char *cp
= line
+ 3;
147 if (isspace ((int) *cp
))
149 /* deal with spaces, $, @ and & */
150 while (!isalnum ((int) *cp
))
152 cp
= skipPrefix (cp
, &scope
);
155 vStringPut (name
, (int) *cp
);
157 } while (isalnum ((int) *cp
) || *cp
== '_');
158 vStringTerminate (name
);
159 makeSimpleTag (name
, VimKinds
, K_VARIABLE
);
164 vStringDelete (name
);
167 extern parserDefinition
* VimParser (void)
169 static const char *const extensions
[] = { "vim", NULL
};
170 parserDefinition
* def
= parserNew ("Vim");
171 def
->kinds
= VimKinds
;
172 def
->kindCount
= KIND_COUNT (VimKinds
);
173 def
->extensions
= extensions
;
174 def
->parser
= findVimTags
;
178 /* vi:set tabstop=4 shiftwidth=4: */