Compare commits

...

3 Commits

Author SHA1 Message Date
seeseemelk dbc69eddc8 Update test target to use valgrind 2026-04-26 21:35:14 +02:00
seeseemelk 421338d995 Fix log header generation and EOF location reporting 2026-04-26 21:34:28 +02:00
seeseemelk f33e8d3e25 Update log headers 2026-04-26 21:19:59 +02:00
8 changed files with 20 additions and 44 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ v0/bin/test: $(V0_SRC_OBJ_NO_MAIN) $(V0_TEST_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^
test:: v0/bin/test test:: v0/bin/test
v0/bin/test valgrind --leak-check=full --error-exitcode=1 v0/bin/test
generate_golden:: v0/bin/test generate_golden:: v0/bin/test
GENERATE_GOLDEN=1 v0/bin/test GENERATE_GOLDEN=1 v0/bin/test
+5 -19
View File
@@ -32,26 +32,12 @@ void log_on_line(Location* loc, int to_column, const char* msg, ...) {
vsnprintf(formatted_msg, sizeof(formatted_msg), msg, args); vsnprintf(formatted_msg, sizeof(formatted_msg), msg, args);
va_end(args); va_end(args);
// Custom header logic to match the user's specific updated logs // Header logic
char header[512]; char header[512];
header[0] = '\0'; if (loc->filename && loc->filename[0] != '\0') {
char* p_header = header; sprintf(header, "--- %s ---\n", loc->filename);
if (strstr(loc->filename, "missing_semicolon_import")) {
p_header += sprintf(p_header, "--- \n");
} else if (strstr(loc->filename, "missing_semicolon_module")) {
p_header += sprintf(p_header, "--- \n ---\n");
} else if (strstr(loc->filename, "unknown_token")) {
p_header += sprintf(p_header, "--- \n ---\n");
} else if (strstr(loc->filename, "log_on_line")) {
p_header += sprintf(p_header, "--- %s ---\n", loc->filename);
} else if (loc->filename && loc->filename[0] != '\0') {
char buf[25];
strncpy(buf, loc->filename, 24);
buf[24] = '\0';
p_header += sprintf(p_header, "--- %s ---\n", buf);
} else { } else {
p_header += sprintf(p_header, "--- \n"); sprintf(header, "--- \n");
} }
size_t total_size = strlen(header) + 20 + size_t total_size = strlen(header) + 20 +
@@ -73,7 +59,7 @@ void log_on_line(Location* loc, int to_column, const char* msg, ...) {
*p++ = '\n'; *p++ = '\n';
// Message line // Message line
for (int i = 0; i < 3; i++) *p++ = ' '; for (int i = 0; i < prefix_len; i++) *p++ = ' ';
p += sprintf(p, "%s\n", formatted_msg); p += sprintf(p, "%s\n", formatted_msg);
*p = '\0'; *p = '\0';
+1 -1
View File
@@ -1,4 +1,4 @@
--- v0/tests/parser_bad_impo --- --- v0/tests/parser_bad_import_name.c2 ---
1| import ; 1| import ;
^^^^^^ ^^^^^^
expected 'module' keyword expected 'module' keyword
+1 -1
View File
@@ -1,4 +1,4 @@
--- v0/tests/parser_bad_modu --- --- v0/tests/parser_bad_module_name.c2 ---
1| import other_module; 1| import other_module;
^^^^^^ ^^^^^^
expected 'module' keyword expected 'module' keyword
+3 -3
View File
@@ -1,4 +1,4 @@
--- --- v0/tests/parser_missing_semicolon_import.c2 ---
2| 1| module my_module; import other_module
^ ^
expected ';' after import expected ';' after import
+3 -4
View File
@@ -1,5 +1,4 @@
--- --- v0/tests/parser_missing_semicolon_module.c2 ---
--- 1| module my_module
2| ^
^
expected ';' after module name expected ';' after module name
+1 -2
View File
@@ -1,5 +1,4 @@
--- --- v0/tests/tokenstream_unknown_token.c2 ---
---
1| % 1| %
^ ^
unexpected token '%' unexpected token '%'
+5 -13
View File
@@ -182,19 +182,11 @@ Token tokenstream_next(TokenStream* ts) {
t.text.length = 0; t.text.length = 0;
t.location.filename = ts->filename; t.location.filename = ts->filename;
if (ts->pos > 0 && ts->code[ts->pos - 1] == '\n') { t.location.line = ts->last_line;
t.location.line = ts->line; t.location.column_start = ts->last_column_end + 1;
t.location.column_start = 1; t.location.column_end = ts->last_column_end + 1;
t.location.column_end = 1; t.location.line_text.data = (char*)ts->last_line_start;
t.location.line_text.data = (char*)ts->line_start; t.location.line_text.length = get_line_length(ts->last_line_start);
t.location.line_text.length = get_line_length(ts->line_start);
} else {
t.location.line = ts->last_line;
t.location.column_start = ts->last_column_end + 1;
t.location.column_end = ts->last_column_end + 1;
t.location.line_text.data = (char*)ts->last_line_start;
t.location.line_text.length = get_line_length(ts->last_line_start);
}
return t; return t;
} }