Use non-symlinked VTE libraries on macOS (#1625)
[geany-mirror.git] / ctags / parsers / haxe.c
blob762c80d1a523492d724662f19d2bc1ad809eb362
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"
26 #include "routines.h"
29 * MACROS
31 #define isType(token,t) (bool) ((token)->type == (t))
32 #define isKeyword(token,k) (bool) ((token)->keyword == (k))
35 * DATA DEFINITIONS
38 /*static jmp_buf Exception;*/
40 typedef enum {
41 HXTAG_METHODS,
42 HXTAG_CLASS,
43 HXTAG_ENUM,
44 HXTAG_VARIABLE,
45 HXTAG_INTERFACE,
46 HXTAG_TYPEDEF,
47 HXTAG_COUNT
48 } hxKind;
50 static kindOption HxKinds [] = {
51 { true, 'm', "method", "methods" },
52 { true, 'c', "class", "classes" },
53 { true, 'e', "enum", "enumerations" },
54 { true, 'v', "variable", "variables" },
55 { true, 'i', "interface", "interfaces" },
56 { true, 't', "typedef", "typedefs" },
59 static void findHxTags (void)
61 vString *name = vStringNew ();
62 vString *clsName = vStringNew();
63 vString *scope2 = vStringNew();
64 vString *laccess = vStringNew();
65 const char *const priv = "private";
66 const char *const pub = "public";
68 const unsigned char *line;
70 while ((line = readLineFromInputFile ()) != NULL)
72 const unsigned char *cp = line;
73 another:
74 while (isspace (*cp))
75 cp++;
77 vStringCopyS(laccess,priv);
79 if (strncmp ((const char*) cp, "var", (size_t) 3) == 0 &&
80 isspace ((int) cp [3]))
82 cp += 3;
84 while (isspace ((int) *cp))
85 ++cp;
87 vStringClear (name);
88 while (isalnum ((int) *cp) || *cp == '_')
90 vStringPut (name, (int) *cp);
91 ++cp;
93 makeSimpleTag (name, HxKinds, HXTAG_VARIABLE);
95 vStringClear (name);
97 else if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
98 isspace ((int) cp [8]))
100 cp += 8;
102 while (isspace ((int) *cp))
103 ++cp;
105 vStringClear (name);
106 while (isalnum ((int) *cp) || *cp == '_')
108 vStringPut (name, (int) *cp);
109 ++cp;
111 makeSimpleTag (name, HxKinds, HXTAG_METHODS);
113 vStringClear (name);
115 else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0 &&
116 isspace ((int) cp [5]))
118 cp += 5;
120 while (isspace ((int) *cp))
121 ++cp;
122 vStringClear (name);
123 while (isalnum ((int) *cp) || *cp == '_')
125 vStringPut (name, (int) *cp);
126 ++cp;
128 makeSimpleTag (name, HxKinds, HXTAG_CLASS);
129 vStringCopy(clsName,name);
130 vStringClear (name);
132 else if (strncmp ((const char*) cp, "enum", (size_t) 4) == 0 &&
133 isspace ((int) cp [4]))
135 cp += 4;
137 while (isspace ((int) *cp))
138 ++cp;
139 vStringClear (name);
140 while (isalnum ((int) *cp) || *cp == '_')
142 vStringPut (name, (int) *cp);
143 ++cp;
145 makeSimpleTag (name, HxKinds, HXTAG_ENUM);
146 vStringClear (name);
147 } else if (strncmp ((const char*) cp, "public", (size_t) 6) == 0 &&
148 isspace((int) cp [6]))
150 cp += 6;
151 while (isspace ((int) *cp))
152 ++cp;
153 vStringCopyS(laccess,pub);
154 goto another;
155 } else if (strncmp ((const char*) cp, "static", (size_t) 6) == 0 &&
156 isspace((int) cp [6]))
158 cp += 6;
159 while (isspace ((int) *cp))
160 ++cp;
161 goto another;
162 } else if (strncmp ((const char*) cp, "interface", (size_t) 9) == 0 &&
163 isspace((int) cp [9]))
165 cp += 9;
167 while (isspace ((int) *cp))
168 ++cp;
169 vStringClear (name);
170 while (isalnum ((int) *cp) || *cp == '_') {
171 vStringPut (name, (int) *cp);
172 ++cp;
174 makeSimpleTag (name, HxKinds, HXTAG_INTERFACE);
175 vStringClear (name);
176 } else if (strncmp ((const char *) cp,"typedef",(size_t) 7) == 0 && isspace(((int) cp[7]))) {
177 cp += 7;
179 while (isspace ((int) *cp))
180 ++cp;
181 vStringClear (name);
182 while (isalnum ((int) *cp) || *cp == '_') {
183 vStringPut (name, (int) *cp);
184 ++cp;
186 makeSimpleTag (name, HxKinds, HXTAG_TYPEDEF);
187 vStringClear (name);
193 vStringDelete(name);
194 vStringDelete(clsName);
195 vStringDelete(scope2);
196 vStringDelete(laccess);
200 /* Create parser definition structure */
201 extern parserDefinition* HaxeParser (void)
203 static const char *const extensions [] = { "hx", NULL };
205 parserDefinition *const def = parserNew ("Haxe");
206 def->extensions = extensions;
208 * New definitions for parsing instead of regex
210 def->kinds = HxKinds;
211 def->kindCount = ARRAY_SIZE (HxKinds);
212 def->parser = findHxTags;
213 /*def->initialize = initialize;*/
214 return def;