From 90bc830a9a46186e19504164072c3bdac140f550 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 8 Aug 2019 20:27:24 -0300 Subject: [PATCH] lang: show line where error happened --- src/image.zig | 2 +- src/lang.zig | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/image.zig b/src/image.zig index e031c5a..17a545d 100644 --- a/src/image.zig +++ b/src/image.zig @@ -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); diff --git a/src/lang.zig b/src/lang.zig index 882cac9..79d38d0 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -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;