diff options
author | Marvin Borner | 2021-04-27 16:24:24 +0200 |
---|---|---|
committer | Marvin Borner | 2021-04-27 16:24:24 +0200 |
commit | 7c047df78502d53411fef09c6e39540d2b7e796a (patch) | |
tree | 00a72bb40f81e7294cb1dde776159ed219ee4967 /src/lexer.c | |
parent | 60e7b5069d5936546356053f85008a5a02bb473a (diff) |
Fixed some overflows and enabled live parsing
Diffstat (limited to 'src/lexer.c')
-rw-r--r-- | src/lexer.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lexer.c b/src/lexer.c index 5b43cb5..9efe957 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <def.h> #include <lexer.h> #include <stdio.h> @@ -16,8 +17,13 @@ void token_print(struct token *tok) { - if (!tok->length) + // Something terrible needs to happen to make this true + assert(tok->length || tok->type == END); + + if (tok->type == END) { + printf("\\0 (%d)\n", tok->type); return; + } char swp = tok->start[tok->length]; tok->start[tok->length] = 0; @@ -47,6 +53,9 @@ struct token token_resolve(char *str, u32 size) } else if (str[0] == '\n') { type = NEWLINE; length = 1; + } else if (str[0] == '\0') { + type = END; + length = 0; // Well } else if (str[0] == ' ') { type = SPACE; length = 1; |