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.
13 #include "general.h" /* must always come first */
14 #include <ctype.h> /* to define isalpha () */
31 #define isType(token,t) (bool) ((token)->type == (t))
32 #define isKeyword(token,k) (bool) ((token)->keyword == (k))
38 /*static jmp_buf Exception;*/
50 static kindDefinition 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
;
77 vStringCopyS(laccess
,priv
);
79 if (strncmp ((const char*) cp
, "var", (size_t) 3) == 0 &&
80 isspace ((int) cp
[3]))
84 while (isspace ((int) *cp
))
88 while (isalnum ((int) *cp
) || *cp
== '_')
90 vStringPut (name
, (int) *cp
);
93 makeSimpleTag (name
, HXTAG_VARIABLE
);
97 else if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
98 isspace ((int) cp
[8]))
102 while (isspace ((int) *cp
))
106 while (isalnum ((int) *cp
) || *cp
== '_')
108 vStringPut (name
, (int) *cp
);
111 makeSimpleTag (name
, HXTAG_METHODS
);
115 else if (strncmp ((const char*) cp
, "class", (size_t) 5) == 0 &&
116 isspace ((int) cp
[5]))
120 while (isspace ((int) *cp
))
123 while (isalnum ((int) *cp
) || *cp
== '_')
125 vStringPut (name
, (int) *cp
);
128 makeSimpleTag (name
, HXTAG_CLASS
);
129 vStringCopy(clsName
,name
);
132 else if (strncmp ((const char*) cp
, "enum", (size_t) 4) == 0 &&
133 isspace ((int) cp
[4]))
137 while (isspace ((int) *cp
))
140 while (isalnum ((int) *cp
) || *cp
== '_')
142 vStringPut (name
, (int) *cp
);
145 makeSimpleTag (name
, HXTAG_ENUM
);
147 } else if (strncmp ((const char*) cp
, "public", (size_t) 6) == 0 &&
148 isspace((int) cp
[6]))
151 while (isspace ((int) *cp
))
153 vStringCopyS(laccess
,pub
);
155 } else if (strncmp ((const char*) cp
, "static", (size_t) 6) == 0 &&
156 isspace((int) cp
[6]))
159 while (isspace ((int) *cp
))
162 } else if (strncmp ((const char*) cp
, "interface", (size_t) 9) == 0 &&
163 isspace((int) cp
[9]))
167 while (isspace ((int) *cp
))
170 while (isalnum ((int) *cp
) || *cp
== '_') {
171 vStringPut (name
, (int) *cp
);
174 makeSimpleTag (name
, HXTAG_INTERFACE
);
176 } else if (strncmp ((const char *) cp
,"typedef",(size_t) 7) == 0 && isspace(((int) cp
[7]))) {
179 while (isspace ((int) *cp
))
182 while (isalnum ((int) *cp
) || *cp
== '_') {
183 vStringPut (name
, (int) *cp
);
186 makeSimpleTag (name
, HXTAG_TYPEDEF
);
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
->kindTable
= HxKinds
;
211 def
->kindCount
= ARRAY_SIZE (HxKinds
);
212 def
->parser
= findHxTags
;
213 /*def->initialize = initialize;*/