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 () */
30 #define isType(token,t) (bool) ((token)->type == (t))
31 #define isKeyword(token,k) (bool) ((token)->keyword == (k))
37 /*static jmp_buf Exception;*/
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
;
76 vStringCopyS(laccess
,priv
);
78 if (strncmp ((const char*) cp
, "var", (size_t) 3) == 0 &&
79 isspace ((int) cp
[3]))
83 while (isspace ((int) *cp
))
87 while (isalnum ((int) *cp
) || *cp
== '_')
89 vStringPut (name
, (int) *cp
);
92 makeSimpleTag (name
, HXTAG_VARIABLE
);
96 else if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
97 isspace ((int) cp
[8]))
101 while (isspace ((int) *cp
))
105 while (isalnum ((int) *cp
) || *cp
== '_')
107 vStringPut (name
, (int) *cp
);
110 makeSimpleTag (name
, HXTAG_METHODS
);
114 else if (strncmp ((const char*) cp
, "class", (size_t) 5) == 0 &&
115 isspace ((int) cp
[5]))
119 while (isspace ((int) *cp
))
122 while (isalnum ((int) *cp
) || *cp
== '_')
124 vStringPut (name
, (int) *cp
);
127 makeSimpleTag (name
, HXTAG_CLASS
);
128 vStringCopy(clsName
,name
);
131 else if (strncmp ((const char*) cp
, "enum", (size_t) 4) == 0 &&
132 isspace ((int) cp
[4]))
136 while (isspace ((int) *cp
))
139 while (isalnum ((int) *cp
) || *cp
== '_')
141 vStringPut (name
, (int) *cp
);
144 makeSimpleTag (name
, HXTAG_ENUM
);
146 } else if (strncmp ((const char*) cp
, "public", (size_t) 6) == 0 &&
147 isspace((int) cp
[6]))
150 while (isspace ((int) *cp
))
152 vStringCopyS(laccess
,pub
);
154 } else if (strncmp ((const char*) cp
, "static", (size_t) 6) == 0 &&
155 isspace((int) cp
[6]))
158 while (isspace ((int) *cp
))
161 } else if (strncmp ((const char*) cp
, "interface", (size_t) 9) == 0 &&
162 isspace((int) cp
[9]))
166 while (isspace ((int) *cp
))
169 while (isalnum ((int) *cp
) || *cp
== '_') {
170 vStringPut (name
, (int) *cp
);
173 makeSimpleTag (name
, HXTAG_INTERFACE
);
175 } else if (strncmp ((const char *) cp
,"typedef",(size_t) 7) == 0 && isspace(((int) cp
[7]))) {
178 while (isspace ((int) *cp
))
181 while (isalnum ((int) *cp
) || *cp
== '_') {
182 vStringPut (name
, (int) *cp
);
185 makeSimpleTag (name
, HXTAG_TYPEDEF
);
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;*/