From 023c39c1f1d9000bb9d549289b8f826fae5476dc Mon Sep 17 00:00:00 2001 From: _N3m0 Date: Mon, 1 Jan 2024 19:13:39 +0100 Subject: [PATCH] MORE TOKEN --- lexer.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++---------- lexer.h | 3 +++ 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/lexer.c b/lexer.c index fb4035d..5e9c035 100644 --- a/lexer.c +++ b/lexer.c @@ -1,6 +1,4 @@ #include "lexer.h" -#include "page.h" -#include Cursor cursor = { .chunk = 0, @@ -22,31 +20,84 @@ char* nextchar(void){ return &page.chunks[cursor.chunk][cursor.offset]; } +char* HTMLbalise(void){ + return NULL; +} + Token* nexttoken(void){ Token* token = malloc(sizeof(Token)); - token->type = NO_TYPE; + token->value = NULL; - puts(""); - char* c = nextchar(); - do { - printf("%c", *c); - c = nextchar(); - } while (c != NULL); - puts(""); + char* word = HTMLbalise(); + if (word == NULL){ + token->type = NO_TYPE; + } else if (strcmp(word, "body") == 0){ + token->type = BODY; + } else if (strcmp(word, "/body") == 0){ + token->type = END_BODY; + } else if (strcmp(word, "ul") == 0){ + token->type = UL; + } else if (strcmp(word, "li") == 0){ + token->type = LI; + } else if (strcmp(word, "h1") == 0){ + token->type = H1; + } else if (strcmp(word, "h2") == 0){ + token->type = H2; + } else if (strcmp(word, "h3") == 0){ + token->type = H3; + } else if (strcmp(word, "h4") == 0){ + token->type = H4; + } else if (strcmp(word, "h5") == 0){ + token->type = H5; + } else if (strcmp(word, "h6") == 0){ + token->type = H6; + } else { + token->type = NO_TYPE; + } return token; } void printtoken(Token* token){ switch (token->type) { - case END_BODY: - printf("END_BODY: "); - break; case NO_TYPE: printf("NO_TYPE: "); break; + case TEXT: + printf("TEXT: "); + break; + case BODY: + printf("BODY: "); + break; + case END_BODY: + printf("END_BODY: "); + break; + case UL: + printf("UL: "); + break; + case LI: + printf("LI: "); + break; + case H1: + printf("H1: "); + break; + case H2: + printf("H2: "); + break; + case H3: + printf("H3: "); + break; + case H4: + printf("H4: "); + break; + case H5: + printf("H5: "); + break; + case H6: + printf("H6: "); + break; default: - printf("OTHER_TOKEN: "); + printf("UNDEFINED TOKEN: "); break; } diff --git a/lexer.h b/lexer.h index 402b36d..a3bfec4 100644 --- a/lexer.h +++ b/lexer.h @@ -3,6 +3,9 @@ #include #include +#include + +#include "page.h" typedef enum TokenType { NO_TYPE,