From 9a4942fd78a6a79046ea3b4f2eff2db798b3b0f6 Mon Sep 17 00:00:00 2001 From: Fernando Araoz Date: Tue, 24 Dec 2024 19:11:23 -0500 Subject: [PATCH] feat: wire error handling into repl flow --- CHANGELOG.md | 1 + src/errors/root.zig | 1 - src/main.zig | 7 +++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c27bd8..4c2fd8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,5 +35,6 @@ Now in Zig! - [x] Parse minimal variable binding - [x] Parse minimal statement - [x] Parse minimal module +- [x] Generate error messages diff --git a/src/errors/root.zig b/src/errors/root.zig index 0d7046d..9bf184c 100644 --- a/src/errors/root.zig +++ b/src/errors/root.zig @@ -145,7 +145,6 @@ test "should get line from 2 lines (3)" { } test "should gen error message" { - // get_error_str const source = "print(ehh)"; var err = ErrorData{ .reason = "Invalid identifier", diff --git a/src/main.zig b/src/main.zig index 7c6a253..06b32de 100644 --- a/src/main.zig +++ b/src/main.zig @@ -76,9 +76,12 @@ fn repl() !void { } // Print errors - for (error_array.items) |err| { - try stdout.print("Lex error: {s} at pos {d}\n", .{ err.reason, err.start_position }); + for (error_array.items) |e| { + var err = e; + const err_str = try err.get_error_str(line, "repl", std.heap.page_allocator); + try stdout.print("\n{s}\n", .{err_str}); try bw.flush(); + std.heap.page_allocator.free(err_str); } // next repl line