diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-10-09 16:01:31 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-10-14 12:09:28 +0200 |
commit | 6ad05263426e6f4aae4665d52b9ed1962ab4cd24 (patch) | |
tree | 7b73f563e291eeab944071e0c9a3b9128e924c6b /lib.c | |
parent | 4d1c4e28b8d8368a105717e142f8e920cbf4ea0f (diff) |
lexer: rewrite
Rewrite the lexer into a restartable state machine to support parsing from
file streams without the need to read the entire source text into memory
first.
As a side effect, the length of labels and strings is unlimited now.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -171,7 +171,7 @@ char * ut_format_error(struct ut_state *state, const char *expr) { char *msg = NULL, *filename = state->filename; - size_t off = state ? state->off : 0; + size_t off = state ? state->lex.off : 0; struct ut_op *tag; bool first = true; size_t msglen = 0; @@ -217,20 +217,20 @@ ut_format_error(struct ut_state *state, const char *expr) sprintf_append(&msg, &msglen, "Syntax error: Unexpected token\n"); for (i = 0, max_i = 0; i < sizeof(state->error.info.tokens) * 8; i++) - if (ut_is_error_token(state, i) && tokennames[i]) + if (ut_is_error_token(state, i)) max_i = i; for (i = 0; i < sizeof(state->error.info.tokens) * 8; i++) { - if (ut_is_error_token(state, i) && tokennames[i]) { + if (ut_is_error_token(state, i)) { if (first) { - sprintf_append(&msg, &msglen, "Expecting %s", tokennames[i]); + sprintf_append(&msg, &msglen, "Expecting %s", ut_get_tokenname(i)); first = false; } else if (i < max_i) { - sprintf_append(&msg, &msglen, ", %s", tokennames[i]); + sprintf_append(&msg, &msglen, ", %s", ut_get_tokenname(i)); } else { - sprintf_append(&msg, &msglen, " or %s", tokennames[i]); + sprintf_append(&msg, &msglen, " or %s", ut_get_tokenname(i)); } } } |