-static int lex_skipcmt(struct lex_file *file) {
- int ch;
- lex_clear(file);
- ch = lex_getch(file);
-
- if (ch == '/') {
- lex_addch('/', file);
- lex_addch('/', file);
-
- while ((ch = lex_getch(file)) != '\n') {
- if (ch == '\\') {
- lex_addch(ch, file);
- lex_addch(lex_getch(file), file);
- } else {
- lex_addch(ch, file);
- }
- }
- lex_addch('\0', file);
- return LEX_COMMENT;
- }
-
- if (ch != '*') {
- lex_unget(ch, file);
- return '/';
- }
-
- lex_addch('/', file);
-
- /* hate this */
- do {
- lex_addch(ch, file);
- while ((ch = lex_getch(file)) != '*') {
- if (ch == EOF)
- return error(ERROR_LEX, "malformatted comment at line", "");
- else
- lex_addch(ch, file);
- }
- lex_addch(ch, file);
- } while ((ch = lex_getch(file)) != '/');
-
- lex_addch('/', file);
- lex_addch('\0', file);
-
- return LEX_COMMENT;
+
+int lex_token(lex_file *file) {
+ int ch = lex_getsource(file);
+ int it;
+
+ /* valid identifier */
+ if (ch > 0 && (ch == '_' || isalpha(ch))) {
+ lex_clear(file);
+
+ /*
+ * Yes this is dirty, but there is no other _sane_ easy
+ * way to do it, this is what I call defensive programming
+ * if something breaks, add more defense :-)
+ */
+ while (ch > 0 && ch != ' ' && ch != '(' &&
+ ch != '\n' && ch != ';' && ch != ')') {
+ lex_addch(ch, file);
+ ch = lex_getsource(file);
+ }
+ lex_unget(ch, file);
+ lex_addch('\0', file);
+
+ /* look inside the table for a keyword .. */
+ for (it = 0; it < sizeof(lex_keywords)/sizeof(*lex_keywords); it++)
+ if (!strncmp(file->lastok, lex_keywords[it], strlen(lex_keywords[it])))
+ return it;
+
+ /* try a type? */
+ #define TEST_TYPE(X) \
+ do { \
+ if (!strncmp(X, "float", sizeof("float"))) \
+ return TOKEN_FLOAT; \
+ if (!strncmp(X, "vector", sizeof("vector"))) \
+ return TOKEN_VECTOR; \
+ if (!strncmp(X, "string", sizeof("string"))) \
+ return TOKEN_STRING; \
+ if (!strncmp(X, "entity", sizeof("entity"))) \
+ return TOKEN_ENTITY; \
+ if (!strncmp(X, "void" , sizeof("void"))) \
+ return TOKEN_VOID; \
+ } while(0)
+
+ TEST_TYPE(file->lastok);
+
+ /* try the hashtable for typedefs? */
+ if (typedef_find(file->lastok))
+ TEST_TYPE(typedef_find(file->lastok)->name);
+
+ #undef TEST_TYPE
+ return LEX_IDENT;
+ }
+ return ch;