MORE TOKEN

This commit is contained in:
_N3m0 2024-01-01 19:13:39 +01:00
parent 75219aa15c
commit 023c39c1f1
2 changed files with 68 additions and 14 deletions

79
lexer.c
View File

@ -1,6 +1,4 @@
#include "lexer.h" #include "lexer.h"
#include "page.h"
#include <string.h>
Cursor cursor = { Cursor cursor = {
.chunk = 0, .chunk = 0,
@ -22,31 +20,84 @@ char* nextchar(void){
return &page.chunks[cursor.chunk][cursor.offset]; return &page.chunks[cursor.chunk][cursor.offset];
} }
char* HTMLbalise(void){
return NULL;
}
Token* nexttoken(void){ Token* nexttoken(void){
Token* token = malloc(sizeof(Token)); Token* token = malloc(sizeof(Token));
token->type = NO_TYPE; token->value = NULL;
puts(""); char* word = HTMLbalise();
char* c = nextchar(); if (word == NULL){
do { token->type = NO_TYPE;
printf("%c", *c); } else if (strcmp(word, "body") == 0){
c = nextchar(); token->type = BODY;
} while (c != NULL); } else if (strcmp(word, "/body") == 0){
puts(""); 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; return token;
} }
void printtoken(Token* token){ void printtoken(Token* token){
switch (token->type) { switch (token->type) {
case END_BODY:
printf("END_BODY: ");
break;
case NO_TYPE: case NO_TYPE:
printf("NO_TYPE: "); printf("NO_TYPE: ");
break; 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: default:
printf("OTHER_TOKEN: "); printf("UNDEFINED TOKEN: ");
break; break;
} }

View File

@ -3,6 +3,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "page.h"
typedef enum TokenType { typedef enum TokenType {
NO_TYPE, NO_TYPE,