X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=lexer.c;h=bb601215fb11b2e97ae7a07a9e4355eec2e9ab31;hb=09a1a375546b8ecd946aa8a1055f1583ac316a51;hp=e1cff47ef24bfd19b2ff7c27a14d1b450f846724;hpb=03b933bc7a20f22d22c0d62bc49b3b9d5fb8a03d;p=xonotic%2Fgmqcc.git diff --git a/lexer.c b/lexer.c index e1cff47..bb60121 100644 --- a/lexer.c +++ b/lexer.c @@ -184,7 +184,7 @@ static void lex_token_new(lex_file *lex) lex_file* lex_open(const char *file) { lex_file *lex; - FILE *in = file_open(file, "rb"); + FILE *in = fs_file_open(file, "rb"); if (!in) { lexerror(NULL, "open failed: '%s'\n", file); @@ -193,7 +193,7 @@ lex_file* lex_open(const char *file) lex = (lex_file*)mem_a(sizeof(*lex)); if (!lex) { - file_close(in); + fs_file_close(in); lexerror(NULL, "out of memory\n"); return NULL; } @@ -258,7 +258,7 @@ void lex_close(lex_file *lex) vec_free(lex->modelname); if (lex->file) - file_close(lex->file); + fs_file_close(lex->file); #if 0 if (lex->tok) token_delete(lex->tok); @@ -1289,15 +1289,22 @@ int lex_do(lex_file *lex) if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */ ch == '>' || ch == '<' || /* <<, >>, <=, >= */ - ch == '=' || ch == '!' || /* ==, != */ + ch == '=' || ch == '!' || /* <=>, ==, != */ ch == '&' || ch == '|' || /* &&, ||, &=, |= */ ch == '~' /* ~=, ~ */ ) { lex_tokench(lex, ch); nextch = lex_getch(lex); - if (nextch == '=' || (nextch == ch && ch != '!')) { + if ((nextch == '=' && ch != '<') || (nextch == ch && ch != '!')) { lex_tokench(lex, nextch); + } else if (ch == '<' && nextch == '=') { + lex_tokench(lex, nextch); + if ((thirdch = lex_getch(lex)) == '>') + lex_tokench(lex, thirdch); + else + lex_ungetch(lex, thirdch); + } else if (ch == '-' && nextch == '>') { lex_tokench(lex, nextch); } else if (ch == '&' && nextch == '~') { @@ -1321,8 +1328,9 @@ int lex_do(lex_file *lex) lex->tok.constval.f = -lex->tok.constval.f; lex_endtoken(lex); return lex->tok.ttype; - } else + } else { lex_ungetch(lex, nextch); + } lex_endtoken(lex); return (lex->tok.ttype = TOKEN_OPERATOR); @@ -1485,6 +1493,6 @@ int lex_do(lex_file *lex) return (lex->tok.ttype = ch); } - lexerror(lex, "unknown token: %c", lex->tok); + lexerror(lex, "unknown token: `%s`", lex->tok.value); return (lex->tok.ttype = TOKEN_ERROR); }