pass file into flex instead of content buffer

This commit is contained in:
2025-05-30 12:56:25 +01:00
parent 68341db0b0
commit ddf18ceb2c
4 changed files with 2007367 additions and 38 deletions

View File

@@ -4,49 +4,18 @@
#include "memory.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
char* read_file_as_text(const char* filename) {
FILE *file = fopen(filename, "r");
if (!file) {
perror("Failed to open file");
return NULL;
}
// Seek to the end to find the file size
fseek(file, 0, SEEK_END);
long length = ftell(file);
rewind(file); // Go back to the beginning
// Allocate buffer (+1 for null terminator)
char *buffer = malloc(length + 1);
if (!buffer) {
perror("Failed to allocate memory");
fclose(file);
return NULL;
}
// Read the whole file into the buffer
size_t read_size = fread(buffer, 1, length, file);
buffer[read_size] = '\0'; // Null-terminate
fclose(file);
return buffer;
}
int main() {
ar_memory_init();
const char * path = "test.ar";
char *content = read_file_as_text(path);
LinkedList* tokens = create_list(sizeof(Token));
if (!content) return 1;
LexerState state = {
path,
content,
fopen(path, "r"),
0,
tokens
};
@@ -60,5 +29,7 @@ int main() {
free_list(parsed,free_tagged_value);
ar_memory_init();
return 0;
}