feat: wire error handling into repl flow
This commit is contained in:
parent
4e13453930
commit
9a4942fd78
@ -35,5 +35,6 @@ Now in Zig!
|
|||||||
- [x] Parse minimal variable binding
|
- [x] Parse minimal variable binding
|
||||||
- [x] Parse minimal statement
|
- [x] Parse minimal statement
|
||||||
- [x] Parse minimal module
|
- [x] Parse minimal module
|
||||||
|
- [x] Generate error messages
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,7 +145,6 @@ test "should get line from 2 lines (3)" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "should gen error message" {
|
test "should gen error message" {
|
||||||
// get_error_str
|
|
||||||
const source = "print(ehh)";
|
const source = "print(ehh)";
|
||||||
var err = ErrorData{
|
var err = ErrorData{
|
||||||
.reason = "Invalid identifier",
|
.reason = "Invalid identifier",
|
||||||
|
@ -76,9 +76,12 @@ fn repl() !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print errors
|
// Print errors
|
||||||
for (error_array.items) |err| {
|
for (error_array.items) |e| {
|
||||||
try stdout.print("Lex error: {s} at pos {d}\n", .{ err.reason, err.start_position });
|
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();
|
try bw.flush();
|
||||||
|
std.heap.page_allocator.free(err_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// next repl line
|
// next repl line
|
||||||
|
Loading…
Reference in New Issue
Block a user