From 71ced998122c357bc62e54d9bb4e124c88acf94b Mon Sep 17 00:00:00 2001 From: nasr Date: Sun, 8 Mar 2026 21:01:43 +0000 Subject: refactor(main): worked on string handling in C and other stuff --- source/lexer/lexer.c | 100 --------------------------------------------------- source/lexer/lexer.h | 23 ------------ 2 files changed, 123 deletions(-) delete mode 100644 source/lexer/lexer.c delete mode 100644 source/lexer/lexer.h (limited to 'source/lexer') diff --git a/source/lexer/lexer.c b/source/lexer/lexer.c deleted file mode 100644 index 948afd0..0000000 --- a/source/lexer/lexer.c +++ /dev/null @@ -1,100 +0,0 @@ -// the lexer acts as a table builder from a csv file -// and parsing indivudal rows and columns -// the next step would be building a the b-tree -internal b32 -is_alpha(u8 point) -{ - return ((point >= 'a' && point <= 'z') || (point >= 'A' && point <= 'Z') || (point == '_')); -} - -internal b32 -is_digit(u8 point) -{ - return (point >= '0' && point <= '9'); -} - -internal b32 -is_alpha_num(u8 point) -{ - return (is_alpha(point) || is_digit(point)); -} - -internal b32 -is_whitespace(u8 point) -{ - return (point == '\n' || point == '\r' || point == ' ' || point == '\t'); -} - -internal b32 -is_delimiter(u8 point) -{ - return (point == ','); -} - -internal token * -tokenize_csv(string8 buffer, csv_table *global_table, mem_arena *arena) -{ - i32 count = 0; - string8 **tokens = PushArray(arena, string8 *, buffer.size / 10); - b32 first_line = 1; - - if(buffer.size < 0) return NULL; - for(i32 index = 0; - buffer.data[index] != '\0'; - ++index) - { - csv_row *row = PushStruct(arena, csv_row); - string8 token = {0}; - - u8 point = buffer.data[index]; - - u8 *start = buffer.data; - u8 *end = NULL; - - unused(row); - - switch (point) - { - case '\n': - { - first_line = -1; - break; - } - case ',': - { - end = start - 1; - - if (first_line) - { - global_table->headers = &token; - ++global_table->headers; - break; - } - else - { - - break; - } - } - - default: - { - printf("point: %c\n", point); - count++; - break; - } - } - - token = (string8){ - .data = start, - .size = end - start, - }; - - **tokens = token; - ++*tokens; - } - - printf("%d", count); - - return NULL; -} diff --git a/source/lexer/lexer.h b/source/lexer/lexer.h deleted file mode 100644 index 86f8427..0000000 --- a/source/lexer/lexer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ENGINE_LEXER_H -#define ENGINE_LEXER_H - -typedef enum token_type token_type; -enum token_type -{ - // first 255 tokens for ascii characters - TOKEN_UNDEFINED = 255, - TOKEN_IDENTIFIER, - TOKEN_VALUE, - -}; - -typedef struct token token; -struct token -{ - string8 lexeme; - token_type type; - -}; - - -#endif /* ENGINE_LEXER_H */ -- cgit v1.3