Create branch for 0.19.1 release (copied from 0.19).
[geany-mirror.git] / tagmanager / haxe.c
blob932acc0f4e2ba7529eedfc1a3e885d5fff4b1cd1
1 /*
2 * Copyright (c) 2007, Ritchie Turner
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License.
7 * borrowed from PHP
8 */
11 * INCLUDE FILES
13 #include "general.h" /* must always come first */
14 #include <ctype.h> /* to define isalpha () */
15 #include <setjmp.h>
16 #ifdef DEBUG
17 #include <stdio.h>
18 #endif
19 #include <string.h>
20 #include "main.h"
21 #include "entry.h"
22 #include "keyword.h"
23 #include "parse.h"
24 #include "read.h"
25 #include "vstring.h"
28 * MACROS
30 #define isType(token,t) (boolean) ((token)->type == (t))
31 #define isKeyword(token,k) (boolean) ((token)->keyword == (k))
34 * DATA DEFINITIONS
37 /*static jmp_buf Exception;*/
39 typedef enum {
40 HXTAG_METHODS,
41 HXTAG_CLASS,
42 HXTAG_ENUM,
43 HXTAG_VARIABLE,
44 HXTAG_INTERFACE,
45 HXTAG_TYPEDEF,
46 HXTAG_COUNT
47 } hxKind;
49 static kindOption HxKinds [] = {
50 { TRUE, 'm', "method", "methods" },
51 { TRUE, 'c', "class", "classes" },
52 { TRUE, 'e', "enum", "enumerations" },
53 { TRUE, 'v', "variable", "variables" },
54 { TRUE, 'i', "interface", "interfaces" },
55 { TRUE, 't', "typedef", "typedefs" },
58 static void findHxTags (void)
60 vString *name = vStringNew ();
61 vString *clsName = vStringNew();
62 vString *scope2 = vStringNew();
63 vString *laccess = vStringNew();
64 const char *const priv = "private";
65 const char *const pub = "public";
67 const unsigned char *line;
69 while ((line = fileReadLine ()) != NULL)
71 const unsigned char *cp = line;
72 another:
73 while (isspace (*cp))
74 cp++;
76 vStringCopyS(laccess,priv);
78 if (strncmp ((const char*) cp, "var", (size_t) 3) == 0 &&
79 isspace ((int) cp [3]))
81 cp += 3;
83 while (isspace ((int) *cp))
84 ++cp;
86 vStringClear (name);
87 while (isalnum ((int) *cp) || *cp == '_')
89 vStringPut (name, (int) *cp);
90 ++cp;
92 vStringTerminate (name);
93 makeSimpleTag (name, HxKinds, HXTAG_VARIABLE);
95 makeSimpleScopedTag(name, HxKinds,
96 HXTAG_VARIABLE,vStringValue(clsName),
97 strdup(vStringValue(scope2)),strdup(vStringValue(laccess)));
100 vStringClear (name);
102 else if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
103 isspace ((int) cp [8]))
105 cp += 8;
107 while (isspace ((int) *cp))
108 ++cp;
110 vStringClear (name);
111 while (isalnum ((int) *cp) || *cp == '_')
113 vStringPut (name, (int) *cp);
114 ++cp;
116 vStringTerminate (name);
117 makeSimpleTag (name, HxKinds, HXTAG_METHODS);
119 makeSimpleScopedTag(name, HxKinds, HXTAG_METHODS,
120 strdup(vStringValue(clsName)),strdup(vStringValue(scope2)),strdup(vStringValue(laccess)));
124 vStringClear (name);
126 else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0 &&
127 isspace ((int) cp [5]))
129 cp += 5;
131 while (isspace ((int) *cp))
132 ++cp;
133 vStringClear (name);
134 while (isalnum ((int) *cp) || *cp == '_')
136 vStringPut (name, (int) *cp);
137 ++cp;
139 vStringTerminate (name);
140 makeSimpleTag (name, HxKinds, HXTAG_CLASS);
141 vStringCopy(clsName,name);
142 vStringClear (name);
144 else if (strncmp ((const char*) cp, "enum", (size_t) 4) == 0 &&
145 isspace ((int) cp [4]))
147 cp += 4;
149 while (isspace ((int) *cp))
150 ++cp;
151 vStringClear (name);
152 while (isalnum ((int) *cp) || *cp == '_')
154 vStringPut (name, (int) *cp);
155 ++cp;
157 vStringTerminate (name);
158 makeSimpleTag (name, HxKinds, HXTAG_ENUM);
159 vStringClear (name);
160 } else if (strncmp ((const char*) cp, "public", (size_t) 6) == 0 &&
161 isspace((int) cp [6]))
163 cp += 6;
164 while (isspace ((int) *cp))
165 ++cp;
166 vStringCopyS(laccess,pub);
167 goto another;
168 } else if (strncmp ((const char*) cp, "static", (size_t) 6) == 0 &&
169 isspace((int) cp [6]))
171 cp += 6;
172 while (isspace ((int) *cp))
173 ++cp;
174 goto another;
175 } else if (strncmp ((const char*) cp, "interface", (size_t) 9) == 0 &&
176 isspace((int) cp [9]))
178 cp += 9;
180 while (isspace ((int) *cp))
181 ++cp;
182 vStringClear (name);
183 while (isalnum ((int) *cp) || *cp == '_') {
184 vStringPut (name, (int) *cp);
185 ++cp;
187 vStringTerminate (name);
188 makeSimpleTag (name, HxKinds, HXTAG_INTERFACE);
189 vStringClear (name);
190 } else if (strncmp ((const char *) cp,"typedef",(size_t) 7) == 0 && isspace(((int) cp[7]))) {
191 cp += 7;
193 while (isspace ((int) *cp))
194 ++cp;
195 vStringClear (name);
196 while (isalnum ((int) *cp) || *cp == '_') {
197 vStringPut (name, (int) *cp);
198 ++cp;
200 vStringTerminate (name);
201 makeSimpleTag (name, HxKinds, HXTAG_TYPEDEF);
202 vStringClear (name);
208 vStringDelete(name);
209 vStringDelete(clsName);
210 vStringDelete(scope2);
211 vStringDelete(laccess);
215 /* Create parser definition stucture */
216 extern parserDefinition* HaxeParser (void)
218 static const char *const extensions [] = { "hx", NULL };
220 parserDefinition *const def = parserNew ("Haxe");
221 def->extensions = extensions;
223 * New definitions for parsing instead of regex
225 def->kinds = HxKinds;
226 def->kindCount = KIND_COUNT (HxKinds);
227 def->parser = findHxTags;
228 /*def->initialize = initialize;*/
229 return def;