lang: do as many semantic errors as possible before ParseFail

This commit is contained in:
Luna 2019-08-08 20:30:24 -03:00
parent 90bc830a9a
commit a0bf1e2723

View file

@ -292,6 +292,7 @@ pub const Lang = struct {
try self.fillKeywords(); try self.fillKeywords();
var cmds = CommandList.init(self.allocator); var cmds = CommandList.init(self.allocator);
var idx: usize = 0; var idx: usize = 0;
var has_error = false;
while (splitted_it.next()) |stmt_orig| { while (splitted_it.next()) |stmt_orig| {
var stmt = std.mem.trimRight(u8, stmt_orig, "\n"); var stmt = std.mem.trimRight(u8, stmt_orig, "\n");
@ -328,13 +329,15 @@ pub const Lang = struct {
cmd_ptr.* = Command{ .command = ctype, .args = args }; cmd_ptr.* = Command{ .command = ctype, .args = args };
self.validateCommand(cmd_ptr) catch |err| { self.validateCommand(cmd_ptr) catch |err| {
std.debug.warn("error at line {}: {}\n", idx, err); std.debug.warn("error at line {}: {}\n", idx, err);
return ParseError.ParseFail; has_error = true;
}; };
try cmds.append(cmd_ptr); try cmds.append(cmd_ptr);
idx += 1; idx += 1;
} }
if (has_error) return ParseError.ParseFail;
return cmds; return cmds;
} }
}; };