ctags.rb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/Gemfile +2 -0
  2. data/Rakefile +23 -0
  3. data/ctags.rb.gemspec +23 -0
  4. data/ext/.gitignore +3 -0
  5. data/ext/extconf.rb +15 -0
  6. data/ext/vendor/exuberant-ctags/.gitignore +6 -0
  7. data/ext/vendor/exuberant-ctags/.indent.pro +31 -0
  8. data/ext/vendor/exuberant-ctags/COPYING +340 -0
  9. data/ext/vendor/exuberant-ctags/EXTENDING.html +386 -0
  10. data/ext/vendor/exuberant-ctags/FAQ +371 -0
  11. data/ext/vendor/exuberant-ctags/INSTALL +215 -0
  12. data/ext/vendor/exuberant-ctags/INSTALL.oth +73 -0
  13. data/ext/vendor/exuberant-ctags/MAINTAINERS +88 -0
  14. data/ext/vendor/exuberant-ctags/Makefile.in +222 -0
  15. data/ext/vendor/exuberant-ctags/NEWS +871 -0
  16. data/ext/vendor/exuberant-ctags/README +73 -0
  17. data/ext/vendor/exuberant-ctags/ant.c +42 -0
  18. data/ext/vendor/exuberant-ctags/argproc.c +505 -0
  19. data/ext/vendor/exuberant-ctags/args.c +274 -0
  20. data/ext/vendor/exuberant-ctags/args.h +63 -0
  21. data/ext/vendor/exuberant-ctags/asm.c +387 -0
  22. data/ext/vendor/exuberant-ctags/asp.c +328 -0
  23. data/ext/vendor/exuberant-ctags/awk.c +81 -0
  24. data/ext/vendor/exuberant-ctags/basic.c +203 -0
  25. data/ext/vendor/exuberant-ctags/beta.c +321 -0
  26. data/ext/vendor/exuberant-ctags/c.c +2932 -0
  27. data/ext/vendor/exuberant-ctags/cobol.c +50 -0
  28. data/ext/vendor/exuberant-ctags/config.h.in +277 -0
  29. data/ext/vendor/exuberant-ctags/configure +7704 -0
  30. data/ext/vendor/exuberant-ctags/configure.ac +532 -0
  31. data/ext/vendor/exuberant-ctags/ctags.1 +1186 -0
  32. data/ext/vendor/exuberant-ctags/ctags.h +28 -0
  33. data/ext/vendor/exuberant-ctags/ctags.html +2087 -0
  34. data/ext/vendor/exuberant-ctags/ctags.spec +40 -0
  35. data/ext/vendor/exuberant-ctags/debug.c +113 -0
  36. data/ext/vendor/exuberant-ctags/debug.h +70 -0
  37. data/ext/vendor/exuberant-ctags/descrip.mms +68 -0
  38. data/ext/vendor/exuberant-ctags/dosbatch.c +42 -0
  39. data/ext/vendor/exuberant-ctags/e_amiga.h +24 -0
  40. data/ext/vendor/exuberant-ctags/e_djgpp.h +47 -0
  41. data/ext/vendor/exuberant-ctags/e_mac.h +143 -0
  42. data/ext/vendor/exuberant-ctags/e_msoft.h +76 -0
  43. data/ext/vendor/exuberant-ctags/e_os2.h +37 -0
  44. data/ext/vendor/exuberant-ctags/e_qdos.h +34 -0
  45. data/ext/vendor/exuberant-ctags/e_riscos.h +58 -0
  46. data/ext/vendor/exuberant-ctags/e_vms.h +31 -0
  47. data/ext/vendor/exuberant-ctags/eiffel.c +1352 -0
  48. data/ext/vendor/exuberant-ctags/entry.c +847 -0
  49. data/ext/vendor/exuberant-ctags/entry.h +103 -0
  50. data/ext/vendor/exuberant-ctags/erlang.c +189 -0
  51. data/ext/vendor/exuberant-ctags/flex.c +2243 -0
  52. data/ext/vendor/exuberant-ctags/fortran.c +2197 -0
  53. data/ext/vendor/exuberant-ctags/general.h +127 -0
  54. data/ext/vendor/exuberant-ctags/get.c +669 -0
  55. data/ext/vendor/exuberant-ctags/get.h +50 -0
  56. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/all-wcprops +47 -0
  57. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/entries +112 -0
  58. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/README.txt.svn-base +5 -0
  59. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regcomp.c.svn-base +3818 -0
  60. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex.c.svn-base +74 -0
  61. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex.h.svn-base +575 -0
  62. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex_internal.c.svn-base +1713 -0
  63. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex_internal.h.svn-base +773 -0
  64. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regexec.c.svn-base +4338 -0
  65. data/ext/vendor/exuberant-ctags/gnu_regex/README.txt +5 -0
  66. data/ext/vendor/exuberant-ctags/gnu_regex/regcomp.c +3818 -0
  67. data/ext/vendor/exuberant-ctags/gnu_regex/regex.c +74 -0
  68. data/ext/vendor/exuberant-ctags/gnu_regex/regex.h +575 -0
  69. data/ext/vendor/exuberant-ctags/gnu_regex/regex_internal.c +1713 -0
  70. data/ext/vendor/exuberant-ctags/gnu_regex/regex_internal.h +773 -0
  71. data/ext/vendor/exuberant-ctags/gnu_regex/regexec.c +4338 -0
  72. data/ext/vendor/exuberant-ctags/html.c +49 -0
  73. data/ext/vendor/exuberant-ctags/jscript.c +1572 -0
  74. data/ext/vendor/exuberant-ctags/keyword.c +258 -0
  75. data/ext/vendor/exuberant-ctags/keyword.h +34 -0
  76. data/ext/vendor/exuberant-ctags/lisp.c +139 -0
  77. data/ext/vendor/exuberant-ctags/lregex.c +704 -0
  78. data/ext/vendor/exuberant-ctags/lua.c +133 -0
  79. data/ext/vendor/exuberant-ctags/mac.c +273 -0
  80. data/ext/vendor/exuberant-ctags/magic.diff +21 -0
  81. data/ext/vendor/exuberant-ctags/main.c +584 -0
  82. data/ext/vendor/exuberant-ctags/main.h +32 -0
  83. data/ext/vendor/exuberant-ctags/maintainer.mak +476 -0
  84. data/ext/vendor/exuberant-ctags/make.c +217 -0
  85. data/ext/vendor/exuberant-ctags/matlab.c +44 -0
  86. data/ext/vendor/exuberant-ctags/mk_bc3.mak +46 -0
  87. data/ext/vendor/exuberant-ctags/mk_bc5.mak +49 -0
  88. data/ext/vendor/exuberant-ctags/mk_djg.mak +18 -0
  89. data/ext/vendor/exuberant-ctags/mk_manx.mak +65 -0
  90. data/ext/vendor/exuberant-ctags/mk_mingw.mak +31 -0
  91. data/ext/vendor/exuberant-ctags/mk_mpw.mak +130 -0
  92. data/ext/vendor/exuberant-ctags/mk_mvc.mak +40 -0
  93. data/ext/vendor/exuberant-ctags/mk_os2.mak +104 -0
  94. data/ext/vendor/exuberant-ctags/mk_qdos.mak +100 -0
  95. data/ext/vendor/exuberant-ctags/mk_sas.mak +63 -0
  96. data/ext/vendor/exuberant-ctags/mkinstalldirs +40 -0
  97. data/ext/vendor/exuberant-ctags/ocaml.c +1842 -0
  98. data/ext/vendor/exuberant-ctags/options.c +1842 -0
  99. data/ext/vendor/exuberant-ctags/options.h +155 -0
  100. data/ext/vendor/exuberant-ctags/parse.c +677 -0
  101. data/ext/vendor/exuberant-ctags/parse.h +129 -0
  102. data/ext/vendor/exuberant-ctags/parsers.h +63 -0
  103. data/ext/vendor/exuberant-ctags/pascal.c +267 -0
  104. data/ext/vendor/exuberant-ctags/perl.c +382 -0
  105. data/ext/vendor/exuberant-ctags/php.c +237 -0
  106. data/ext/vendor/exuberant-ctags/python.c +771 -0
  107. data/ext/vendor/exuberant-ctags/qdos.c +106 -0
  108. data/ext/vendor/exuberant-ctags/read.c +569 -0
  109. data/ext/vendor/exuberant-ctags/read.h +116 -0
  110. data/ext/vendor/exuberant-ctags/readtags.c +959 -0
  111. data/ext/vendor/exuberant-ctags/readtags.h +252 -0
  112. data/ext/vendor/exuberant-ctags/rexx.c +39 -0
  113. data/ext/vendor/exuberant-ctags/routines.c +891 -0
  114. data/ext/vendor/exuberant-ctags/routines.h +134 -0
  115. data/ext/vendor/exuberant-ctags/ruby.c +408 -0
  116. data/ext/vendor/exuberant-ctags/scheme.c +111 -0
  117. data/ext/vendor/exuberant-ctags/sh.c +115 -0
  118. data/ext/vendor/exuberant-ctags/slang.c +41 -0
  119. data/ext/vendor/exuberant-ctags/sml.c +212 -0
  120. data/ext/vendor/exuberant-ctags/sort.c +230 -0
  121. data/ext/vendor/exuberant-ctags/sort.h +32 -0
  122. data/ext/vendor/exuberant-ctags/source.mak +122 -0
  123. data/ext/vendor/exuberant-ctags/sql.c +2112 -0
  124. data/ext/vendor/exuberant-ctags/strlist.c +281 -0
  125. data/ext/vendor/exuberant-ctags/strlist.h +54 -0
  126. data/ext/vendor/exuberant-ctags/tcl.c +116 -0
  127. data/ext/vendor/exuberant-ctags/tex.c +524 -0
  128. data/ext/vendor/exuberant-ctags/verilog.c +340 -0
  129. data/ext/vendor/exuberant-ctags/vhdl.c +835 -0
  130. data/ext/vendor/exuberant-ctags/vim.c +636 -0
  131. data/ext/vendor/exuberant-ctags/vstring.c +232 -0
  132. data/ext/vendor/exuberant-ctags/vstring.h +85 -0
  133. data/ext/vendor/exuberant-ctags/yacc.c +40 -0
  134. data/lib/ctags/exuberant.rb +45 -0
  135. data/lib/ctags/version.rb +3 -0
  136. data/lib/ctags.rb +6 -0
  137. data/test/test_ctags.rb +24 -0
  138. metadata +233 -0
@@ -0,0 +1,328 @@
1
+ /*
2
+ * $Id: asp.c 711 2009-07-04 16:52:11Z dhiebert $
3
+ *
4
+ * Copyright (c) 2000, Patrick Dehne <patrick@steidle.net>
5
+ *
6
+ * This source code is released for free distribution under the terms of the
7
+ * GNU General Public License.
8
+ *
9
+ * This module contains functions for generating tags for the ASP (Active
10
+ * Server Pages) web page scripting language.
11
+ */
12
+
13
+ /*
14
+ * INCLUDE FILES
15
+ */
16
+ #include "general.h" /* must always come first */
17
+
18
+ #include <string.h>
19
+
20
+ #include "parse.h"
21
+ #include "read.h"
22
+ #include "vstring.h"
23
+
24
+ /*
25
+ * DATA DEFINITIONS
26
+ */
27
+ typedef enum {
28
+ K_CONST, K_CLASS, K_FUNCTION, K_SUB, K_DIM
29
+ } aspKind;
30
+
31
+ static kindOption AspKinds [] = {
32
+ { TRUE, 'd', "constant", "constants"},
33
+ { TRUE, 'c', "class", "classes"},
34
+ { TRUE, 'f', "function", "functions"},
35
+ { TRUE, 's', "subroutine", "subroutines"},
36
+ { TRUE, 'v', "variable", "variables"}
37
+ };
38
+
39
+ /*
40
+ * FUNCTION DEFINITIONS
41
+ */
42
+
43
+ static void findAspTags (void)
44
+ {
45
+ vString *name = vStringNew ();
46
+ const unsigned char *line;
47
+
48
+ while ((line = fileReadLine ()) != NULL)
49
+ {
50
+ const unsigned char *cp = line;
51
+
52
+ while (*cp != '\0')
53
+ {
54
+ /* jump over whitespace */
55
+ while (isspace ((int)*cp))
56
+ cp++;
57
+
58
+ /* jump over strings */
59
+ if (*cp == '"')
60
+ {
61
+ cp++;
62
+ while (*cp!='"' && *cp!='\0')
63
+ cp++;
64
+ }
65
+
66
+ /* jump over comments */
67
+ else if (*cp == '\'')
68
+ break;
69
+
70
+ /* jump over end function/sub lines */
71
+ else if (strncasecmp ((const char*) cp, "end", (size_t) 3)== 0)
72
+ {
73
+ cp += 3;
74
+ if (isspace ((int)*cp))
75
+ {
76
+ while (isspace ((int)*cp))
77
+ ++cp;
78
+
79
+ if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
80
+ {
81
+ cp+=8;
82
+ break;
83
+ }
84
+
85
+ else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
86
+ {
87
+ cp+=3;
88
+ break;
89
+ }
90
+ }
91
+ }
92
+
93
+ /* jump over exit function/sub lines */
94
+ else if (strncasecmp ((const char*) cp, "exit", (size_t) 4)==0)
95
+ {
96
+ cp += 4;
97
+ if (isspace ((int) *cp))
98
+ {
99
+ while (isspace ((int) *cp))
100
+ ++cp;
101
+
102
+ if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
103
+ {
104
+ cp+=8;
105
+ break;
106
+ }
107
+
108
+ else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
109
+ {
110
+ cp+=3;
111
+ break;
112
+ }
113
+ }
114
+ }
115
+
116
+ /* class member? */
117
+ else if (strncasecmp ((const char*) cp, "public", (size_t) 6) == 0)
118
+ {
119
+ cp += 6;
120
+ if (isspace ((int) *cp))
121
+ {
122
+ while (isspace ((int) *cp))
123
+ ++cp;
124
+ if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
125
+ {
126
+ cp+=8;
127
+ while (isspace ((int) *cp))
128
+ ++cp;
129
+ while (isalnum ((int) *cp) || *cp == '_')
130
+ {
131
+ vStringPut (name, (int) *cp);
132
+ ++cp;
133
+ }
134
+ vStringTerminate (name);
135
+ makeSimpleTag (name, AspKinds, K_FUNCTION);
136
+ vStringClear (name);
137
+ }
138
+ else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
139
+ {
140
+ cp+=3;
141
+ while (isspace ((int) *cp))
142
+ ++cp;
143
+ while (isalnum ((int) *cp) || *cp == '_')
144
+ {
145
+ vStringPut (name, (int) *cp);
146
+ ++cp;
147
+ }
148
+ vStringTerminate (name);
149
+ makeSimpleTag (name, AspKinds, K_SUB);
150
+ vStringClear (name);
151
+ }
152
+ else {
153
+ while (isalnum ((int) *cp) || *cp == '_')
154
+ {
155
+ vStringPut (name, (int) *cp);
156
+ ++cp;
157
+ }
158
+ vStringTerminate (name);
159
+ makeSimpleTag (name, AspKinds, K_DIM);
160
+ vStringClear (name);
161
+ }
162
+ }
163
+ }
164
+ else if (strncasecmp ((const char*) cp, "private", (size_t) 7) == 0)
165
+ {
166
+ cp += 7;
167
+ if (isspace ((int) *cp))
168
+ {
169
+ while (isspace ((int) *cp))
170
+ ++cp;
171
+ if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
172
+ {
173
+ cp+=8;
174
+ while (isspace ((int) *cp))
175
+ ++cp;
176
+ while (isalnum ((int) *cp) || *cp == '_')
177
+ {
178
+ vStringPut (name, (int) *cp);
179
+ ++cp;
180
+ }
181
+ vStringTerminate (name);
182
+ makeSimpleTag (name, AspKinds, K_FUNCTION);
183
+ vStringClear (name);
184
+ }
185
+ else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
186
+ {
187
+ cp+=3;
188
+ while (isspace ((int) *cp))
189
+ ++cp;
190
+ while (isalnum ((int) *cp) || *cp == '_')
191
+ {
192
+ vStringPut (name, (int) *cp);
193
+ ++cp;
194
+ }
195
+ vStringTerminate (name);
196
+ makeSimpleTag (name, AspKinds, K_SUB);
197
+ vStringClear (name);
198
+ }
199
+ else {
200
+ while (isalnum ((int) *cp) || *cp == '_')
201
+ {
202
+ vStringPut (name, (int) *cp);
203
+ ++cp;
204
+ }
205
+ vStringTerminate (name);
206
+ makeSimpleTag (name, AspKinds, K_DIM);
207
+ vStringClear (name);
208
+ }
209
+ }
210
+ }
211
+
212
+ /* function? */
213
+ else if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
214
+ {
215
+ cp += 8;
216
+
217
+ if (isspace ((int) *cp))
218
+ {
219
+ while (isspace ((int) *cp))
220
+ ++cp;
221
+ while (isalnum ((int) *cp) || *cp == '_')
222
+ {
223
+ vStringPut (name, (int) *cp);
224
+ ++cp;
225
+ }
226
+ vStringTerminate (name);
227
+ makeSimpleTag (name, AspKinds, K_FUNCTION);
228
+ vStringClear (name);
229
+ }
230
+ }
231
+
232
+ /* sub? */
233
+ else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
234
+ {
235
+ cp += 3;
236
+ if (isspace ((int) *cp))
237
+ {
238
+ while (isspace ((int) *cp))
239
+ ++cp;
240
+ while (isalnum ((int) *cp) || *cp == '_')
241
+ {
242
+ vStringPut (name, (int) *cp);
243
+ ++cp;
244
+ }
245
+ vStringTerminate (name);
246
+ makeSimpleTag (name, AspKinds, K_SUB);
247
+ vStringClear (name);
248
+ }
249
+ }
250
+
251
+ /* dim variable? */
252
+ else if (strncasecmp ((const char*) cp, "dim", (size_t) 3) == 0)
253
+ {
254
+ cp += 3;
255
+ if (isspace ((int) *cp))
256
+ {
257
+ while (isspace ((int) *cp))
258
+ ++cp;
259
+ while (isalnum ((int) *cp) || *cp == '_')
260
+ {
261
+ vStringPut (name, (int) *cp);
262
+ ++cp;
263
+ }
264
+ vStringTerminate (name);
265
+ makeSimpleTag (name, AspKinds, K_DIM);
266
+ vStringClear (name);
267
+ }
268
+ }
269
+
270
+ /* class declaration? */
271
+ else if (strncasecmp ((const char*) cp, "class", (size_t) 5) == 0)
272
+ {
273
+ cp += 5;
274
+ if (isspace ((int) *cp))
275
+ {
276
+ while (isspace ((int) *cp))
277
+ ++cp;
278
+ while (isalnum ((int) *cp) || *cp == '_')
279
+ {
280
+ vStringPut (name, (int) *cp);
281
+ ++cp;
282
+ }
283
+ vStringTerminate (name);
284
+ makeSimpleTag (name, AspKinds, K_CLASS);
285
+ vStringClear (name);
286
+ }
287
+ }
288
+
289
+ /* const declaration? */
290
+ else if (strncasecmp ((const char*) cp, "const", (size_t) 5) == 0)
291
+ {
292
+ cp += 5;
293
+ if (isspace ((int) *cp))
294
+ {
295
+ while (isspace ((int) *cp))
296
+ ++cp;
297
+ while (isalnum ((int) *cp) || *cp == '_')
298
+ {
299
+ vStringPut (name, (int) *cp);
300
+ ++cp;
301
+ }
302
+ vStringTerminate (name);
303
+ makeSimpleTag (name, AspKinds, K_CONST);
304
+ vStringClear (name);
305
+ }
306
+ }
307
+
308
+ /* nothing relevant */
309
+ else if (*cp != '\0')
310
+ cp++;
311
+ }
312
+ }
313
+ vStringDelete (name);
314
+ }
315
+
316
+ extern parserDefinition* AspParser (void)
317
+ {
318
+ static const char *const extensions [] = { "asp", "asa", NULL };
319
+ parserDefinition* def = parserNew ("Asp");
320
+ def->kinds = AspKinds;
321
+ def->kindCount = KIND_COUNT (AspKinds);
322
+ def->extensions = extensions;
323
+ def->parser = findAspTags;
324
+ return def;
325
+ }
326
+
327
+ /* vi:set tabstop=4 shiftwidth=4: */
328
+
@@ -0,0 +1,81 @@
1
+ /*
2
+ * $Id: awk.c 443 2006-05-30 04:37:13Z darren $
3
+ *
4
+ * Copyright (c) 2000-2002, Darren Hiebert
5
+ *
6
+ * This source code is released for free distribution under the terms of the
7
+ * GNU General Public License.
8
+ *
9
+ * This module contains functions for generating tags for AWK functions.
10
+ */
11
+
12
+ /*
13
+ * INCLUDE FILES
14
+ */
15
+ #include "general.h" /* must always come first */
16
+
17
+ #include <string.h>
18
+
19
+ #include "parse.h"
20
+ #include "read.h"
21
+ #include "vstring.h"
22
+
23
+ /*
24
+ * DATA DEFINITIONS
25
+ */
26
+ typedef enum eAwkKinds {
27
+ K_FUNCTION
28
+ } awkKind;
29
+
30
+ static kindOption AwkKinds [] = {
31
+ { TRUE, 'f', "function", "functions" }
32
+ };
33
+
34
+ /*
35
+ * FUNCTION DEFINITIONS
36
+ */
37
+
38
+ static void findAwkTags (void)
39
+ {
40
+ vString *name = vStringNew ();
41
+ const unsigned char *line;
42
+
43
+ while ((line = fileReadLine ()) != NULL)
44
+ {
45
+ if (strncmp ((const char*) line, "function", (size_t) 8) == 0 &&
46
+ isspace ((int) line [8]))
47
+ {
48
+ const unsigned char *cp = line + 8;
49
+
50
+ while (isspace ((int) *cp))
51
+ ++cp;
52
+ while (isalnum ((int) *cp) || *cp == '_')
53
+ {
54
+ vStringPut (name, (int) *cp);
55
+ ++cp;
56
+ }
57
+ vStringTerminate (name);
58
+ while (isspace ((int) *cp))
59
+ ++cp;
60
+ if (*cp == '(')
61
+ makeSimpleTag (name, AwkKinds, K_FUNCTION);
62
+ vStringClear (name);
63
+ if (*cp != '\0')
64
+ ++cp;
65
+ }
66
+ }
67
+ vStringDelete (name);
68
+ }
69
+
70
+ extern parserDefinition* AwkParser ()
71
+ {
72
+ static const char *const extensions [] = { "awk", "gawk", "mawk", NULL };
73
+ parserDefinition* def = parserNew ("Awk");
74
+ def->kinds = AwkKinds;
75
+ def->kindCount = KIND_COUNT (AwkKinds);
76
+ def->extensions = extensions;
77
+ def->parser = findAwkTags;
78
+ return def;
79
+ }
80
+
81
+ /* vi:set tabstop=4 shiftwidth=4: */
@@ -0,0 +1,203 @@
1
+ /*
2
+ * $Id:$
3
+ *
4
+ * Copyright (c) 2000-2006, Darren Hiebert, Elias Pschernig
5
+ *
6
+ * This source code is released for free distribution under the terms of the
7
+ * GNU General Public License.
8
+ *
9
+ * This module contains functions for generating tags for BlitzBasic
10
+ * (BlitzMax), PureBasic and FreeBasic language files. For now, this is kept
11
+ * quite simple - but feel free to ask for more things added any time -
12
+ * patches are of course most welcome.
13
+ */
14
+
15
+ /*
16
+ * INCLUDE FILES
17
+ */
18
+ #include "general.h" /* must always come first */
19
+
20
+ #include <string.h>
21
+
22
+ #include "options.h"
23
+ #include "parse.h"
24
+ #include "read.h"
25
+ #include "routines.h"
26
+ #include "vstring.h"
27
+
28
+ /*
29
+ * DATA DEFINITIONS
30
+ */
31
+ typedef enum {
32
+ K_CONST,
33
+ K_FUNCTION,
34
+ K_LABEL,
35
+ K_TYPE,
36
+ K_VARIABLE,
37
+ K_ENUM
38
+ } BasicKind;
39
+
40
+ typedef struct {
41
+ char const *token;
42
+ BasicKind kind;
43
+ int skip;
44
+ } KeyWord;
45
+
46
+ static kindOption BasicKinds[] = {
47
+ {TRUE, 'c', "constant", "constants"},
48
+ {TRUE, 'f', "function", "functions"},
49
+ {TRUE, 'l', "label", "labels"},
50
+ {TRUE, 't', "type", "types"},
51
+ {TRUE, 'v', "variable", "variables"},
52
+ {TRUE, 'g', "enum", "enumerations"}
53
+ };
54
+
55
+ static KeyWord blitzbasic_keywords[] = {
56
+ {"const", K_CONST, 0},
57
+ {"global", K_VARIABLE, 0},
58
+ {"dim", K_VARIABLE, 0},
59
+ {"function", K_FUNCTION, 0},
60
+ {"type", K_TYPE, 0},
61
+ {NULL, 0, 0}
62
+ };
63
+
64
+ static KeyWord purebasic_keywords[] = {
65
+ {"newlist", K_VARIABLE, 0},
66
+ {"global", K_VARIABLE, 0},
67
+ {"dim", K_VARIABLE, 0},
68
+ {"procedure", K_FUNCTION, 0},
69
+ {"interface", K_TYPE, 0},
70
+ {"structure", K_TYPE, 0},
71
+ {NULL, 0, 0}
72
+ };
73
+
74
+ static KeyWord freebasic_keywords[] = {
75
+ {"const", K_CONST, 0},
76
+ {"dim as", K_VARIABLE, 1},
77
+ {"dim", K_VARIABLE, 0},
78
+ {"common", K_VARIABLE, 0},
79
+ {"function", K_FUNCTION, 0},
80
+ {"sub", K_FUNCTION, 0},
81
+ {"private sub", K_FUNCTION, 0},
82
+ {"public sub", K_FUNCTION, 0},
83
+ {"private function", K_FUNCTION, 0},
84
+ {"public function", K_FUNCTION, 0},
85
+ {"type", K_TYPE, 0},
86
+ {"enum", K_ENUM, 0},
87
+ {NULL, 0, 0}
88
+ };
89
+
90
+ /*
91
+ * FUNCTION DEFINITIONS
92
+ */
93
+
94
+ /* Match the name of a tag (function, variable, type, ...) starting at pos. */
95
+ static char const *extract_name (char const *pos, vString * name)
96
+ {
97
+ while (isspace (*pos))
98
+ pos++;
99
+ vStringClear (name);
100
+ for (; *pos && !isspace (*pos) && *pos != '(' && *pos != ','; pos++)
101
+ vStringPut (name, *pos);
102
+ vStringTerminate (name);
103
+ return pos;
104
+ }
105
+
106
+ /* Match a keyword starting at p (case insensitive). */
107
+ static int match_keyword (const char *p, KeyWord const *kw)
108
+ {
109
+ vString *name;
110
+ size_t i;
111
+ int j;
112
+ for (i = 0; i < strlen (kw->token); i++)
113
+ {
114
+ if (tolower (p[i]) != kw->token[i])
115
+ return 0;
116
+ }
117
+ name = vStringNew ();
118
+ p += i;
119
+ for (j = 0; j < 1 + kw->skip; j++)
120
+ {
121
+ p = extract_name (p, name);
122
+ }
123
+ makeSimpleTag (name, BasicKinds, kw->kind);
124
+ vStringDelete (name);
125
+ return 1;
126
+ }
127
+
128
+ /* Match a "label:" style label. */
129
+ static void match_colon_label (char const *p)
130
+ {
131
+ char const *end = p + strlen (p) - 1;
132
+ while (isspace (*end))
133
+ end--;
134
+ if (*end == ':')
135
+ {
136
+ vString *name = vStringNew ();
137
+ vStringNCatS (name, p, end - p);
138
+ makeSimpleTag (name, BasicKinds, K_LABEL);
139
+ vStringDelete (name);
140
+ }
141
+ }
142
+
143
+ /* Match a ".label" style label. */
144
+ static void match_dot_label (char const *p)
145
+ {
146
+ if (*p == '.')
147
+ {
148
+ vString *name = vStringNew ();
149
+ extract_name (p + 1, name);
150
+ makeSimpleTag (name, BasicKinds, K_LABEL);
151
+ vStringDelete (name);
152
+ }
153
+ }
154
+
155
+ static void findBasicTags (void)
156
+ {
157
+ const char *line;
158
+ const char *extension = fileExtension (vStringValue (File.name));
159
+ KeyWord *keywords;
160
+
161
+ if (strcmp (extension, "bb") == 0)
162
+ keywords = blitzbasic_keywords;
163
+ else if (strcmp (extension, "pb") == 0)
164
+ keywords = purebasic_keywords;
165
+ else
166
+ keywords = freebasic_keywords;
167
+
168
+ while ((line = (const char *) fileReadLine ()) != NULL)
169
+ {
170
+ const char *p = line;
171
+ KeyWord const *kw;
172
+
173
+ while (isspace (*p))
174
+ p++;
175
+
176
+ /* Empty line? */
177
+ if (!*p)
178
+ continue;
179
+
180
+ /* In Basic, keywords always are at the start of the line. */
181
+ for (kw = keywords; kw->token; kw++)
182
+ if (match_keyword (p, kw)) break;
183
+
184
+ /* Is it a label? */
185
+ if (strcmp (extension, "bb") == 0)
186
+ match_dot_label (p);
187
+ else
188
+ match_colon_label (p);
189
+ }
190
+ }
191
+
192
+ parserDefinition *BasicParser (void)
193
+ {
194
+ static char const *extensions[] = { "bas", "bi", "bb", "pb", NULL };
195
+ parserDefinition *def = parserNew ("Basic");
196
+ def->kinds = BasicKinds;
197
+ def->kindCount = KIND_COUNT (BasicKinds);
198
+ def->extensions = extensions;
199
+ def->parser = findBasicTags;
200
+ return def;
201
+ }
202
+
203
+ /* vi:set tabstop=4 shiftwidth=4: */