feat: wire error handling into repl flow

This commit is contained in:
Fernando Araoz 2024-12-24 19:11:23 -05:00
parent 4e13453930
commit 9a4942fd78
3 changed files with 6 additions and 3 deletions

View File

@ -35,5 +35,6 @@ Now in Zig!
- [x] Parse minimal variable binding
- [x] Parse minimal statement
- [x] Parse minimal module
- [x] Generate error messages

View File

@ -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",

View File

@ -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