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).
16 #include "general.h" /* must always come first */
17 #include <ctype.h> /* to define isalpha () */
33 #define isType(token,t) (bool) ((token)->type == (t))
34 #define isKeyword(token,k) (bool) ((token)->keyword == (k))
40 /*static jmp_buf Exception;*/
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
;
79 vStringCopyS(laccess
,priv
);
81 if (strncmp ((const char*) cp
, "var", (size_t) 3) == 0 &&
82 isspace ((int) cp
[3]))
86 while (isspace ((int) *cp
))
90 while (isalnum ((int) *cp
) || *cp
== '_')
92 vStringPut (name
, (int) *cp
);
95 makeSimpleTag (name
, HXTAG_VARIABLE
);
99 else if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
100 isspace ((int) cp
[8]))
104 while (isspace ((int) *cp
))
108 while (isalnum ((int) *cp
) || *cp
== '_')
110 vStringPut (name
, (int) *cp
);
113 makeSimpleTag (name
, HXTAG_METHODS
);
117 else if (strncmp ((const char*) cp
, "class", (size_t) 5) == 0 &&
118 isspace ((int) cp
[5]))
122 while (isspace ((int) *cp
))
125 while (isalnum ((int) *cp
) || *cp
== '_')
127 vStringPut (name
, (int) *cp
);
130 makeSimpleTag (name
, HXTAG_CLASS
);
131 vStringCopy(clsName
,name
);
134 else if (strncmp ((const char*) cp
, "enum", (size_t) 4) == 0 &&
135 isspace ((int) cp
[4]))
139 while (isspace ((int) *cp
))
142 while (isalnum ((int) *cp
) || *cp
== '_')
144 vStringPut (name
, (int) *cp
);
147 makeSimpleTag (name
, HXTAG_ENUM
);
149 } else if (strncmp ((const char*) cp
, "public", (size_t) 6) == 0 &&
150 isspace((int) cp
[6]))
153 while (isspace ((int) *cp
))
155 vStringCopyS(laccess
,pub
);
157 } else if (strncmp ((const char*) cp
, "static", (size_t) 6) == 0 &&
158 isspace((int) cp
[6]))
161 while (isspace ((int) *cp
))
164 } else if (strncmp ((const char*) cp
, "interface", (size_t) 9) == 0 &&
165 isspace((int) cp
[9]))
169 while (isspace ((int) *cp
))
172 while (isalnum ((int) *cp
) || *cp
== '_') {
173 vStringPut (name
, (int) *cp
);
176 makeSimpleTag (name
, HXTAG_INTERFACE
);
178 } else if (strncmp ((const char *) cp
,"typedef",(size_t) 7) == 0 && isspace(((int) cp
[7]))) {
181 while (isspace ((int) *cp
))
184 while (isalnum ((int) *cp
) || *cp
== '_') {
185 vStringPut (name
, (int) *cp
);
188 makeSimpleTag (name
, HXTAG_TYPEDEF
);
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;*/