fix: lexer nextchar go out of available chunks

This commit is contained in:
_N3m0 2024-01-01 10:22:59 +01:00
parent 3bdd778b56
commit 18d4c9d9b2
1 changed files with 4 additions and 13 deletions

17
lexer.c
View File

@ -8,13 +8,15 @@ Cursor cursor = {
};
char* nextchar(void){
if (cursor.chunk >= page.len) return NULL;
if (cursor.chunk >= page.len){
return NULL;
}
if (page.chunks[cursor.chunk][cursor.offset+1] == '\0'){
cursor.chunk++;
cursor.offset = 0;
} else {
cursor.offset++;
}
}
return &page.chunks[cursor.chunk][cursor.offset];
}
@ -23,17 +25,6 @@ Token* nexttoken(void){
Token* token = malloc(sizeof(Token));
token->type = NO_TYPE;
/*
while (nextchar() == '<');
char c = '\0';
do {
c = nextchar();
printf("%c", c);;
} while (c != '>');
puts("");
*/
puts("");
char* c = nextchar();
do {