feat: receive error list in parser root
This commit is contained in:
parent
db8756a1d5
commit
b1ada55ff2
@ -41,6 +41,7 @@ pub fn tokenize(
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME: should defer deinit, otherwise we leak memory?
|
||||
var current_error: errors.ErrorData = undefined;
|
||||
|
||||
// attempt to lex a number
|
||||
@ -50,6 +51,8 @@ pub fn tokenize(
|
||||
// add to list of errors
|
||||
try err_arrl.append(current_error);
|
||||
|
||||
// FIXME: should deinit current_error now that its been allocated, otherwise we leak memory?
|
||||
|
||||
// ignore everything until whitespace and loop
|
||||
current_pos = ignore_until_whitespace(input, actual_next_pos);
|
||||
continue;
|
||||
|
@ -27,7 +27,7 @@ pub const Module = struct {
|
||||
tokens: *const TokenStream,
|
||||
pos: usize,
|
||||
allocator: std.mem.Allocator,
|
||||
error_target: *errors.ErrorData,
|
||||
err_arrl: *std.ArrayList(errors.ErrorData),
|
||||
) ParseError!void {
|
||||
var arrl = std.ArrayList(*statement.Statement).init(allocator);
|
||||
errdefer arrl.deinit();
|
||||
@ -48,12 +48,15 @@ pub const Module = struct {
|
||||
switch (e) {
|
||||
error.Unmatched => {
|
||||
// create the error value
|
||||
var error_target: errors.ErrorData = undefined;
|
||||
try error_target.init(
|
||||
"No statement found",
|
||||
current_pos,
|
||||
current_pos + 1,
|
||||
allocator,
|
||||
);
|
||||
defer error_target.deinit();
|
||||
try err_arrl.append(error_target);
|
||||
return error.Unmatched;
|
||||
},
|
||||
else => return e,
|
||||
@ -90,11 +93,8 @@ test "should parse a single statement" {
|
||||
const tokens = try lexic.tokenize(input, std.testing.allocator, &error_list);
|
||||
defer tokens.deinit();
|
||||
|
||||
const error_target = try std.testing.allocator.create(errors.ErrorData);
|
||||
defer std.testing.allocator.destroy(error_target);
|
||||
|
||||
var module: Module = undefined;
|
||||
_ = try module.init(&tokens, 0, std.testing.allocator, error_target);
|
||||
_ = try module.init(&tokens, 0, std.testing.allocator, &error_list);
|
||||
|
||||
defer module.deinit();
|
||||
}
|
||||
@ -106,11 +106,8 @@ test "should clean memory if a statement parsing fails after one item has been i
|
||||
const tokens = try lexic.tokenize(input, std.testing.allocator, &error_list);
|
||||
defer tokens.deinit();
|
||||
|
||||
const error_target = try std.testing.allocator.create(errors.ErrorData);
|
||||
defer std.testing.allocator.destroy(error_target);
|
||||
|
||||
var module: Module = undefined;
|
||||
_ = module.init(&tokens, 0, std.testing.allocator, error_target) catch {
|
||||
_ = module.init(&tokens, 0, std.testing.allocator, &error_list) catch {
|
||||
return;
|
||||
};
|
||||
defer module.deinit();
|
||||
|
13
src/main.zig
13
src/main.zig
@ -96,7 +96,8 @@ fn repl() !void {
|
||||
}
|
||||
}
|
||||
|
||||
// Print errors
|
||||
// Print errors and continue, if any
|
||||
if (error_array.items.len > 0) {
|
||||
for (error_array.items) |e| {
|
||||
var err = e;
|
||||
const err_str = try err.get_error_str(line, "repl", alloc);
|
||||
@ -104,6 +105,16 @@ fn repl() !void {
|
||||
try bw.flush();
|
||||
alloc.free(err_str);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
std.debug.print("should be syntax analizing the tokens...\n", .{});
|
||||
|
||||
//
|
||||
// Syntax analysis
|
||||
//
|
||||
var ast: syntax.Module = undefined;
|
||||
try ast.init(&tokens, 0, alloc, &error_array);
|
||||
|
||||
// next repl line
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user