aboutsummaryrefslogtreecommitdiff
path: root/asm/main.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:39:26 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:39:26 +0000
commit75dc36cd197ab47ffd1dbbad887dd7bac88c8add (patch)
tree913d6c944dd9be9286fe36e5fe7462efb191b539 /asm/main.c
parentfa640f13e8a231ec3a619cc360289828cc4fc114 (diff)
downloadovm-75dc36cd197ab47ffd1dbbad887dd7bac88c8add.tar.gz
ovm-75dc36cd197ab47ffd1dbbad887dd7bac88c8add.tar.bz2
ovm-75dc36cd197ab47ffd1dbbad887dd7bac88c8add.zip
Lexer now returns errors on failure
Currently only for invalid character literals, but still a possible problem.
Diffstat (limited to 'asm/main.c')
-rw-r--r--asm/main.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/asm/main.c b/asm/main.c
index 2f1102b..bfa12e0 100644
--- a/asm/main.c
+++ b/asm/main.c
@@ -41,7 +41,27 @@ int main(int argc, char *argv[])
darr_t buffer = darr_read_file(fp);
fclose(fp);
- token_stream_t tokens = tokenise_buffer(&buffer);
+ token_stream_t tokens = {0};
+ lerr_t lex_error = tokenise_buffer(&buffer, &tokens);
+ if (lex_error)
+ {
+ // Compute the line/newlines by hand
+ size_t column = 0, line = 1;
+ for (size_t i = 0; i < buffer.used; ++i)
+ {
+ if (buffer.data[i] == '\n')
+ {
+ column = 0;
+ ++line;
+ }
+ else
+ ++column;
+ }
+ fprintf(stderr, "%s:%lu:%lu: %s\n", source_file, line, column,
+ lerr_as_cstr(lex_error));
+ ret = 255 - lex_error;
+ goto end;
+ }
#if VERBOSE >= 1
printf("[%sTOKENISER%s]: %lu bytes -> %lu tokens\n", TERM_GREEN, TERM_RESET,
buffer.used, tokens.available);