authorgravatar for greenfork.lists@yandex.comDmitry Matveyev <greenfork.lists@yandex.com> 2021-06-14 22:09:07+06:00
committergravatar for greenfork.lists@yandex.comDmitry Matveyev <greenfork.lists@yandex.com> 2021-06-14 22:09:07+06:00
log382f87abac469db7cbc4968ca03e02cc1af5f6ee
tree59035699a8d4c6367c629a50bd07b9c18c3639ad
parent4173a2bc24af6839f87b4b4dfd5096f34764d7cc

Rewrite printErrMsgToFile to use Message struct from Compilation


1 files changed, 17 insertions(+), 27 deletions(-)

src/main.zig+17-27
...@@ -3227,17 +3227,9 @@ fn printErrMsgToFile(...@@ -3227,17 +3227,9 @@ fn printErrMsgToFile(
3227 file: fs.File,3227 file: fs.File,
3228 color: Color,3228 color: Color,
3229) !void {3229) !void {
3230 const color_on = switch (color) {
3231 .auto => file.isTty(),
3232 .on => true,
3233 .off => false,
3234 };
3235 const lok_token = parse_error.token;3230 const lok_token = parse_error.token;
3236
3237 const token_starts = tree.tokens.items(.start);
3238 const token_tags = tree.tokens.items(.tag);
3239 const first_token_start = token_starts[lok_token];
3240 const start_loc = tree.tokenLocation(0, lok_token);3231 const start_loc = tree.tokenLocation(0, lok_token);
3232 const source_line = tree.source[start_loc.line_start..start_loc.line_end];
32413233
3242 var text_buf = std.ArrayList(u8).init(gpa);3234 var text_buf = std.ArrayList(u8).init(gpa);
3243 defer text_buf.deinit();3235 defer text_buf.deinit();
...@@ -3245,26 +3237,24 @@ fn printErrMsgToFile(...@@ -3245,26 +3237,24 @@ fn printErrMsgToFile(
3245 try tree.renderError(parse_error, writer);3237 try tree.renderError(parse_error, writer);
3246 const text = text_buf.items;3238 const text = text_buf.items;
32473239
3248 const stream = file.writer();3240 const message: Compilation.AllErrors.Message = .{
3249 try stream.print("{s}:{d}:{d}: error: {s}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });3241 .src = .{
3242 .src_path = path,
3243 .msg = text,
3244 .byte_offset = @intCast(u32, start_loc.line_start),
3245 .line = @intCast(u32, start_loc.line),
3246 .column = @intCast(u32, start_loc.column),
3247 .source_line = source_line,
3248 },
3249 };
32503250
3251 if (!color_on) return;3251 const ttyconf: std.debug.TTY.Config = switch (color) {
3252 .auto => std.debug.detectTTYConfig(),
3253 .on => .escape_codes,
3254 .off => .no_color,
3255 };
32523256
3253 // Print \r and \t as one space each so that column counts line up3257 message.renderToStdErr(ttyconf);
3254 for (tree.source[start_loc.line_start..start_loc.line_end]) |byte| {
3255 try stream.writeByte(switch (byte) {
3256 '\r', '\t' => ' ',
3257 else => byte,
3258 });
3259 }
3260 try stream.writeByte('\n');
3261 try stream.writeByteNTimes(' ', start_loc.column);
3262 if (token_tags[lok_token].lexeme()) |lexeme| {
3263 try stream.writeByteNTimes('~', lexeme.len);
3264 try stream.writeByte('\n');
3265 } else {
3266 try stream.writeAll("^\n");
3267 }
3268}3258}
32693259
3270pub const info_zen =3260pub const info_zen =