webpage/lexer.c

60 lines
955 B
C
Raw Normal View History

2023-12-31 14:54:14 +01:00
#include "lexer.h"
#include "page.h"
#include <string.h>
Cursor cursor = {
.chunk = 0,
.offset = 0,
};
char* nextchar(void){
if (page.chunks[cursor.chunk][cursor.offset+1] == '\0'){
cursor.chunk++;
cursor.offset = 0;
} else {
cursor.offset++;
}
2023-12-31 14:54:14 +01:00
if (cursor.chunk >= page.len){
return NULL;
}
2023-12-31 14:54:14 +01:00
return &page.chunks[cursor.chunk][cursor.offset];
}
Token* nexttoken(void){
Token* token = malloc(sizeof(Token));
token->type = NO_TYPE;
puts("");
2023-12-31 18:04:56 +01:00
char* c = nextchar();
do {
printf("%c", *c);
c = nextchar();
} while (c != NULL);
2023-12-31 14:54:14 +01:00
puts("");
return token;
}
void printtoken(Token* token){
switch (token->type) {
case END_BODY:
printf("END_BODY: ");
break;
case NO_TYPE:
printf("NO_TYPE: ");
break;
default:
printf("OTHER_TOKEN: ");
break;
}
if (token->value == NULL){
puts("NO VALUE FOUND");
return;
}
printf("%s\n", token->value);
}