Update HACKING
[geany-mirror.git] / ctags / parsers / haxe.c
blobaa4877fb27ecfe443b797bbf30e91c2f3f2e95d6
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 "entry.h"
21 #include "keyword.h"
22 #include "parse.h"
23 #include "read.h"
24 #include "vstring.h"
25 #include "routines.h"
28 * MACROS
30 #define isType(token,t) (bool) ((token)->type == (t))
31 #define isKeyword(token,k) (bool) ((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 kindDefinition 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 = readLineFromInputFile ()) != 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 makeSimpleTag (name, HXTAG_VARIABLE);
94 vStringClear (name);
96 else if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
97 isspace ((int) cp [8]))
99 cp += 8;
101 while (isspace ((int) *cp))
102 ++cp;
104 vStringClear (name);
105 while (isalnum ((int) *cp) || *cp == '_')
107 vStringPut (name, (int) *cp);
108 ++cp;
110 makeSimpleTag (name, HXTAG_METHODS);
112 vStringClear (name);
114 else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0 &&
115 isspace ((int) cp [5]))
117 cp += 5;
119 while (isspace ((int) *cp))
120 ++cp;
121 vStringClear (name);
122 while (isalnum ((int) *cp) || *cp == '_')
124 vStringPut (name, (int) *cp);
125 ++cp;
127 makeSimpleTag (name, HXTAG_CLASS);
128 vStringCopy(clsName,name);
129 vStringClear (name);
131 else if (strncmp ((const char*) cp, "enum", (size_t) 4) == 0 &&
132 isspace ((int) cp [4]))
134 cp += 4;
136 while (isspace ((int) *cp))
137 ++cp;
138 vStringClear (name);
139 while (isalnum ((int) *cp) || *cp == '_')
141 vStringPut (name, (int) *cp);
142 ++cp;
144 makeSimpleTag (name, HXTAG_ENUM);
145 vStringClear (name);
146 } else if (strncmp ((const char*) cp, "public", (size_t) 6) == 0 &&
147 isspace((int) cp [6]))
149 cp += 6;
150 while (isspace ((int) *cp))
151 ++cp;
152 vStringCopyS(laccess,pub);
153 goto another;
154 } else if (strncmp ((const char*) cp, "static", (size_t) 6) == 0 &&
155 isspace((int) cp [6]))
157 cp += 6;
158 while (isspace ((int) *cp))
159 ++cp;
160 goto another;
161 } else if (strncmp ((const char*) cp, "interface", (size_t) 9) == 0 &&
162 isspace((int) cp [9]))
164 cp += 9;
166 while (isspace ((int) *cp))
167 ++cp;
168 vStringClear (name);
169 while (isalnum ((int) *cp) || *cp == '_') {
170 vStringPut (name, (int) *cp);
171 ++cp;
173 makeSimpleTag (name, HXTAG_INTERFACE);
174 vStringClear (name);
175 } else if (strncmp ((const char *) cp,"typedef",(size_t) 7) == 0 && isspace(((int) cp[7]))) {
176 cp += 7;
178 while (isspace ((int) *cp))
179 ++cp;
180 vStringClear (name);
181 while (isalnum ((int) *cp) || *cp == '_') {
182 vStringPut (name, (int) *cp);
183 ++cp;
185 makeSimpleTag (name, HXTAG_TYPEDEF);
186 vStringClear (name);
192 vStringDelete(name);
193 vStringDelete(clsName);
194 vStringDelete(scope2);
195 vStringDelete(laccess);
199 /* Create parser definition structure */
200 extern parserDefinition* HaxeParser (void)
202 static const char *const extensions [] = { "hx", NULL };
204 parserDefinition *const def = parserNew ("Haxe");
205 def->extensions = extensions;
207 * New definitions for parsing instead of regex
209 def->kindTable = HxKinds;
210 def->kindCount = ARRAY_SIZE (HxKinds);
211 def->parser = findHxTags;
212 /*def->initialize = initialize;*/
213 return def;