Small update of German translation
[geany-mirror.git] / ctags / parsers / haxe.c
blob930c36dc2ee0598b748e580236366c36ddefc112
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 version 2 or (at your opinion) any later version.
7 * This module contains functions for generating tags for Haxe files
8 * (https://en.wikipedia.org/wiki/Haxe).
10 * Borrowed from PHP.
14 * INCLUDE FILES
16 #include "general.h" /* must always come first */
17 #include <ctype.h> /* to define isalpha () */
18 #include <setjmp.h>
19 #ifdef DEBUG
20 #include <stdio.h>
21 #endif
22 #include <string.h>
23 #include "entry.h"
24 #include "keyword.h"
25 #include "parse.h"
26 #include "read.h"
27 #include "vstring.h"
28 #include "routines.h"
31 * MACROS
33 #define isType(token,t) (bool) ((token)->type == (t))
34 #define isKeyword(token,k) (bool) ((token)->keyword == (k))
37 * DATA DEFINITIONS
40 /*static jmp_buf Exception;*/
42 typedef enum {
43 HXTAG_METHODS,
44 HXTAG_CLASS,
45 HXTAG_ENUM,
46 HXTAG_VARIABLE,
47 HXTAG_INTERFACE,
48 HXTAG_TYPEDEF,
49 HXTAG_COUNT
50 } hxKind;
52 static kindDefinition HxKinds [] = {
53 { true, 'm', "method", "methods" },
54 { true, 'c', "class", "classes" },
55 { true, 'e', "enum", "enumerations" },
56 { true, 'v', "variable", "variables" },
57 { true, 'i', "interface", "interfaces" },
58 { true, 't', "typedef", "typedefs" },
61 static void findHxTags (void)
63 vString *name = vStringNew ();
64 vString *clsName = vStringNew();
65 vString *scope2 = vStringNew();
66 vString *laccess = vStringNew();
67 const char *const priv = "private";
68 const char *const pub = "public";
70 const unsigned char *line;
72 while ((line = readLineFromInputFile ()) != NULL)
74 const unsigned char *cp = line;
75 another:
76 while (isspace (*cp))
77 cp++;
79 vStringCopyS(laccess,priv);
81 if (strncmp ((const char*) cp, "var", (size_t) 3) == 0 &&
82 isspace ((int) cp [3]))
84 cp += 3;
86 while (isspace ((int) *cp))
87 ++cp;
89 vStringClear (name);
90 while (isalnum ((int) *cp) || *cp == '_')
92 vStringPut (name, (int) *cp);
93 ++cp;
95 makeSimpleTag (name, HXTAG_VARIABLE);
97 vStringClear (name);
99 else if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
100 isspace ((int) cp [8]))
102 cp += 8;
104 while (isspace ((int) *cp))
105 ++cp;
107 vStringClear (name);
108 while (isalnum ((int) *cp) || *cp == '_')
110 vStringPut (name, (int) *cp);
111 ++cp;
113 makeSimpleTag (name, HXTAG_METHODS);
115 vStringClear (name);
117 else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0 &&
118 isspace ((int) cp [5]))
120 cp += 5;
122 while (isspace ((int) *cp))
123 ++cp;
124 vStringClear (name);
125 while (isalnum ((int) *cp) || *cp == '_')
127 vStringPut (name, (int) *cp);
128 ++cp;
130 makeSimpleTag (name, HXTAG_CLASS);
131 vStringCopy(clsName,name);
132 vStringClear (name);
134 else if (strncmp ((const char*) cp, "enum", (size_t) 4) == 0 &&
135 isspace ((int) cp [4]))
137 cp += 4;
139 while (isspace ((int) *cp))
140 ++cp;
141 vStringClear (name);
142 while (isalnum ((int) *cp) || *cp == '_')
144 vStringPut (name, (int) *cp);
145 ++cp;
147 makeSimpleTag (name, HXTAG_ENUM);
148 vStringClear (name);
149 } else if (strncmp ((const char*) cp, "public", (size_t) 6) == 0 &&
150 isspace((int) cp [6]))
152 cp += 6;
153 while (isspace ((int) *cp))
154 ++cp;
155 vStringCopyS(laccess,pub);
156 goto another;
157 } else if (strncmp ((const char*) cp, "static", (size_t) 6) == 0 &&
158 isspace((int) cp [6]))
160 cp += 6;
161 while (isspace ((int) *cp))
162 ++cp;
163 goto another;
164 } else if (strncmp ((const char*) cp, "interface", (size_t) 9) == 0 &&
165 isspace((int) cp [9]))
167 cp += 9;
169 while (isspace ((int) *cp))
170 ++cp;
171 vStringClear (name);
172 while (isalnum ((int) *cp) || *cp == '_') {
173 vStringPut (name, (int) *cp);
174 ++cp;
176 makeSimpleTag (name, HXTAG_INTERFACE);
177 vStringClear (name);
178 } else if (strncmp ((const char *) cp,"typedef",(size_t) 7) == 0 && isspace(((int) cp[7]))) {
179 cp += 7;
181 while (isspace ((int) *cp))
182 ++cp;
183 vStringClear (name);
184 while (isalnum ((int) *cp) || *cp == '_') {
185 vStringPut (name, (int) *cp);
186 ++cp;
188 makeSimpleTag (name, HXTAG_TYPEDEF);
189 vStringClear (name);
195 vStringDelete(name);
196 vStringDelete(clsName);
197 vStringDelete(scope2);
198 vStringDelete(laccess);
202 /* Create parser definition structure */
203 extern parserDefinition* HaxeParser (void)
205 static const char *const extensions [] = { "hx", NULL };
207 parserDefinition *const def = parserNew ("Haxe");
208 def->extensions = extensions;
210 * New definitions for parsing instead of regex
212 def->kindTable = HxKinds;
213 def->kindCount = ARRAY_SIZE (HxKinds);
214 def->parser = findHxTags;
215 /*def->initialize = initialize;*/
216 return def;