From 854d66bb73cd131bda6452aac74aae3d9a77b91a Mon Sep 17 00:00:00 2001 From: nasr Date: Mon, 9 Mar 2026 19:44:59 +0000 Subject: refactor(main): simplified the project. going towards a single header file project maybe... --- source/engine.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 8 deletions(-) (limited to 'source/engine.c') diff --git a/source/engine.c b/source/engine.c index fe609e9..3527e27 100644 --- a/source/engine.c +++ b/source/engine.c @@ -1,17 +1,88 @@ #define BASE_UNITY #include "base/base_include.h" -#include +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'); +} -#include "csv_parser.h" -#include "lexer.h" +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 == ','); +} + +#include "csv_reader.h" +// #include "btree.h" + +typedef struct query_token query_token; +struct query_token +{ + string8 *lexeme; + query_token *next; +}; + + +// takes on line of the repl input +internal query_token * +query_tokenizer(mem_arena *arena, string8 *buffer) +{ + query_token *tok = PushStruct(arena, query_token); + unused(tok); -#include "lexer.c" -#include "csv_parser.c" + for (u64 index = 0; index < buffer->size; ++index) + { + u8 codepoint = buffer->data[index]; + + if(codepoint == '\n' || codepoint == '\r') break; + + s32 start = 0; + s32 end = 0; + + if(is_whitespace(codepoint)) + { + end = index; + } + + s32 new_token_size = end - start; + + tok->lexeme->data = &buffer->data[index]; + tok->lexeme->size = new_token_size; + + tok->next = tok; + start = index + 1; + + } + + return tok; +} int main(int c, char **v) { - if(c < 2) return -999; + if(c < 2) + { + print("bad file, setting default file\n"); + } + else v[1] = "./test/customers-10000.csv"; local_persist b32 running = 1; @@ -26,13 +97,27 @@ int main(int c, char **v) { if (running) { - // TODO(nasr): check for return key { u8 line_buffer[256] = {}; - s64 codepoint = os_read(STDIN_FD, line_buffer, 256); unused(codepoint); + for(s32 index = 0; index < 256; ++index) + { + if(line_buffer[index] == '\n') + { + print("exiting"); + return 0; + } + else if(line_buffer[index] == ' ') + { + print("TODO(nasr): "); + } + + } + } + + { read_csv(buffer); token *tokens = tokenize_csv(buffer, global_arena); global_table = parse_csv(tokens, global_table); -- cgit v1.3