about summary refs log tree commit diff
path: root/boot/catboot.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-07-09 04:46:58 +0200
committerMel <mel@rnrd.eu>2025-07-09 04:46:58 +0200
commitefa510e6b58ce13c53e94f13a5be0007240e9dcc (patch)
tree7bcebe71e6d90d7e0004be1f975e5028b3c1b530 /boot/catboot.c
parent3620cabd1d722e4acc761c7278aa44aba902006c (diff)
downloadcatskill-efa510e6b58ce13c53e94f13a5be0007240e9dcc.tar.zst
catskill-efa510e6b58ce13c53e94f13a5be0007240e9dcc.zip
Display human-readable, informative parser error messages w/ source snippet
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/catboot.c')
-rw-r--r--boot/catboot.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/boot/catboot.c b/boot/catboot.c
index 53b2bed..ed5831e 100644
--- a/boot/catboot.c
+++ b/boot/catboot.c
@@ -95,24 +95,23 @@ debug_lex_pass(struct String source)
 }
 
 integer
-debug_parse_pass(struct String source)
+debug_parse_pass(struct Source_File source_file)
 {
     struct Lexer lexer;
-    lexer_new(&lexer, source);
+    lexer_new(&lexer, source_file.source);
 
     struct Parser parser;
-    parser_new(&parser, &lexer);
+    parser_new(&parser, &lexer, source_file);
 
-    struct Parser_Error parser_error = parser_error_none();
-    struct Tree tree = parser_do_your_thing(&parser, &parser_error);
-    if (!parser_error_is_none(&parser_error)) {
-        fprintf(stderr, "parser error: %s\n", parser_error_to_string(&parser_error));
-        return 1;
+    struct Tree tree;
+    int parser_result = parser_do_your_thing(&parser, &tree);
+    if (parser_result != 0) {
+        fprintf(stderr, "parser finished with errors\n");
     }
 
     tree_printer(&tree);
 
-    return 0;
+    return parser_result;
 }
 
 enum Command_Result
@@ -155,8 +154,12 @@ enum Command_Result
 test_parse_command(struct Command_Arguments* arguments)
 {
     struct String source = read_file(arguments->input);
+    struct Source_File source_file = {
+        .source = source,
+        .path = string_from_static_c_string(arguments->input),
+    };
 
-    if (debug_parse_pass(source)) return COMMAND_FAIL;
+    if (debug_parse_pass(source_file)) return COMMAND_FAIL;
 
     return COMMAND_OK;
 }
@@ -165,10 +168,14 @@ enum Command_Result
 default_command(struct Command_Arguments* arguments)
 {
     struct String source = read_file(arguments->input);
+    struct Source_File source_file = {
+        .source = source,
+        .path = string_from_static_c_string(arguments->input),
+    };
 
     debug_lex_pass(source);
     printf("\n");
-    if (debug_parse_pass(source)) return COMMAND_FAIL;
+    if (debug_parse_pass(source_file)) return COMMAND_FAIL;
     printf("\n");
 
     return COMMAND_OK;