lang: show line where error happened

This commit is contained in:
Luna 2019-08-08 20:27:24 -03:00
parent ab2e8884b8
commit 90bc830a9a
2 changed files with 8 additions and 2 deletions

View file

@ -193,7 +193,7 @@ pub const Image = struct {
sseek(out_file, start);
while (i <= end) : (i += buf.len) {
std.debug.warn("i={}, buf.len={}, end={}\n", i, buf.len, end);
std.debug.warn("\t\ti={}, buf.len={}, end={}\n", i, buf.len, end);
sseek(self.sndfile, i);
sseek(out_file, i);

View file

@ -7,6 +7,7 @@ pub const ParseError = error{
UnknownCommand,
ArgRequired,
FloatParseFail,
ParseFail,
};
pub const CommandType = enum {
@ -290,6 +291,7 @@ pub const Lang = struct {
var splitted_it = std.mem.separate(data, ";");
try self.fillKeywords();
var cmds = CommandList.init(self.allocator);
var idx: usize = 0;
while (splitted_it.next()) |stmt_orig| {
var stmt = std.mem.trimRight(u8, stmt_orig, "\n");
@ -324,9 +326,13 @@ pub const Lang = struct {
errdefer self.allocator.destroy(cmd_ptr);
cmd_ptr.* = Command{ .command = ctype, .args = args };
try self.validateCommand(cmd_ptr);
self.validateCommand(cmd_ptr) catch |err| {
std.debug.warn("error at line {}: {}\n", idx, err);
return ParseError.ParseFail;
};
try cmds.append(cmd_ptr);
idx += 1;
}
return cmds;