vmfparser.c 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "vmfparser.h"
  2. #include "libc.h"
  3. enum TokenType getNextToken(struct TokenContext *tok) {
  4. enum TokenType type = Token_Skip;
  5. const char *c = tok->cursor;
  6. #define CHECK_END ((tok->end && tok->end == c) || *c == '\0')
  7. while (type == Token_Skip) {
  8. while(!CHECK_END && isspace(*c)) ++c;
  9. if (CHECK_END) return Token_End;
  10. tok->str_start = c;
  11. tok->str_length = 0;
  12. switch(*c) {
  13. case '\"':
  14. tok->str_start = ++c;
  15. while(!CHECK_END && *c != '\"') ++c;
  16. type = (*c == '\"') ? Token_String : Token_Error;
  17. break;
  18. case '{': type = Token_CurlyOpen; break;
  19. case '}': type = Token_CurlyClose; break;
  20. case '/':
  21. if (*++c == '/') {
  22. while(!CHECK_END && *c != '\n') ++c;
  23. type = Token_Skip;
  24. } else
  25. type = Token_Error;
  26. break;
  27. default:
  28. while (!CHECK_END && isgraph(*c)) ++c;
  29. type = (c == tok->str_start) ? Token_Error : Token_String;
  30. } /* switch(*c) */
  31. } /* while skip */
  32. tok->str_length = c - tok->str_start;
  33. tok->cursor = c + 1;
  34. return type;
  35. }