harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 1751c393045cd0ee613ab02077e0687d7ddb27d3
parent c76479f8797dc039116561447c8e16bdc23bc4c5
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Fri, 10 Mar 2023 21:08:02 +0100

lex: s/T_ERROR/T_NONE/

T_ERROR's only use is signaling the lack of an unlexed token. It
doesn't have to do anything with lex errors and encountering it
elsewhere is a compiler bug.

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Minclude/lex.h | 2+-
Msrc/lex.c | 12++++++------
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/lex.h b/include/lex.h @@ -140,7 +140,7 @@ enum lexical_token { // Magic tokens T_EOF, - T_ERROR, + T_NONE, }; struct location { diff --git a/src/lex.c b/src/lex.c @@ -163,7 +163,7 @@ lex_init(struct lexer *lexer, FILE *f, int fileid) lexer->in = f; lexer->bufsz = 256; lexer->buf = xcalloc(1, lexer->bufsz); - lexer->un.token = T_ERROR; + lexer->un.token = T_NONE; lexer->loc.lineno = 1; lexer->loc.colno = 0; lexer->loc.file = fileid; @@ -885,9 +885,9 @@ lex2(struct lexer *lexer, struct token *out, uint32_t c) static enum lexical_token _lex(struct lexer *lexer, struct token *out) { - if (lexer->un.token != T_ERROR) { + if (lexer->un.token != T_NONE) { *out = lexer->un; - lexer->un.token = T_ERROR; + lexer->un.token = T_NONE; return out->token; } @@ -1016,8 +1016,8 @@ lexical_token_str(enum lexical_token tok) return "literal"; case T_EOF: return "end of file"; - case T_ERROR: - return "error"; + case T_NONE: + abort(); default: assert(tok < sizeof(tokens) / sizeof(tokens[0])); return tokens[tok]; @@ -1167,6 +1167,6 @@ token_str(const struct token *tok) void unlex(struct lexer *lexer, struct token *in) { - assert(lexer->un.token == T_ERROR && "Only one unlex is supported"); + assert(lexer->un.token == T_NONE); lexer->un = *in; }