improving lexer

This commit is contained in:
Krzosa Karol
2025-01-17 23:08:52 +01:00
parent a3e6730e0b
commit 63dda7bf13
5 changed files with 204 additions and 63 deletions

View File

@@ -22,14 +22,54 @@ void list_files_recursive(sb8_t *sb, s8_t path) {
}
}
typedef struct c_file_t c_file_t;
struct c_file_t {
c_file_t *next;
s8_t path;
s8_t content;
};
typedef struct c_files_t c_files_t;
struct c_files_t {
c_file_t *first;
c_file_t *last;
};
int main(int argc, char **argv) {
cache_init(&Perm, s8_lit("cache_build_file"));
int ok = 0;
ma_arena_t *arena = ma_create(ma_default_reserve_size);
c_files_t files = {0};
{
sb8_t *c = &(sb8_t){.arena = arena};
list_files_recursive(c, s8_lit(".."));
for (sb8_node_t *it = c->first; it; it = it->next) {
s8_t abs = it->string;
b32 is_c_file = s8_ends_with(abs, s8_lit(".c"), true) || s8_ends_with(abs, s8_lit(".cpp"), true) || s8_ends_with(abs, s8_lit(".h"), true) || s8_ends_with(abs, s8_lit(".hpp"), true);
b32 is_build_file = s8_ends_with(abs, s8_lit("build_file.c"), true);
if (!is_c_file) continue;
if (is_build_file) continue;
c_file_t *file = ma_push_type(arena, c_file_t);
file->path = abs;
file->content = OS_ReadFile(&Perm, abs);
SLLQ_APPEND(files.first, files.last, file);
lex_tokens(arena, file->path.str, file->content);
}
}
meta_app(arena);
meta_ui(arena);
if (cache_code_modified(s8_lit("../src/core/core_math_gen.py"), s8_null)) {
os_set_working_dir("../src/core");
os_systemf("py core_math_gen.py");
os_set_working_dir("../../build");
}
b32 execute_python_snippets = false; // make sure to not abuse just for quick maths
b32 run_server = false;
@@ -37,32 +77,10 @@ int main(int argc, char **argv) {
b32 win32_target = true;
b32 wasm_target = false;
if (cache_code_modified(s8_lit("../src/core/core_math_gen.py"), s8_null)) {
os_set_working_dir("../src/core");
os_systemf("py core_math_gen.py");
os_set_working_dir("../../build");
}
if (execute_python_snippets) {
sb8_t *sb = sb8_serial_begin(arena);
list_files_recursive(sb, s8_lit(".."));
for (sb8_node_t *it = sb->first; it; it = it->next) {
s8_t abs = it->string;
b32 is_c_file = s8_ends_with(abs, s8_lit(".c"), true) || s8_ends_with(abs, s8_lit(".cpp"), true) || s8_ends_with(abs, s8_lit(".h"), true) || s8_ends_with(abs, s8_lit(".hpp"), true);
if (!is_c_file) {
continue;
}
b32 is_build_file = s8_ends_with(abs, s8_lit("build_file.c"), true);
if (is_build_file) {
continue;
}
s8_t file = OS_ReadFile(&Perm, abs);
i64 idx = s8_find(file, s8_lit("/*#"), 0);
if (idx != -1) {
os_systemf("\"D:\\dev\\apps\\bin\\pyorun.bat\" %s", abs.str);
}
for (c_file_t *it = files.first; it; it = it->next) {
i64 idx = s8_find(it->content, s8_lit("/*#"), 0);
if (idx != -1) os_systemf("\"D:\\dev\\apps\\bin\\pyorun.bat\" %s", it->path.str);
}
}