| ... | ... | @@ -3227,17 +3227,9 @@ fn printErrMsgToFile( |
| 3227 | 3227 | file: fs.File, |
| 3228 | 3228 | color: Color, |
| 3229 | 3229 | ) !void { |
| 3230 | | const color_on = switch (color) { |
| 3231 | | .auto => file.isTty(), |
| 3232 | | .on => true, |
| 3233 | | .off => false, |
| 3234 | | }; |
| 3235 | 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 | 3231 | const start_loc = tree.tokenLocation(0, lok_token); |
| 3232 | const source_line = tree.source[start_loc.line_start..start_loc.line_end]; |
| 3241 | 3233 | |
| 3242 | 3234 | var text_buf = std.ArrayList(u8).init(gpa); |
| 3243 | 3235 | defer text_buf.deinit(); |
| ... | ... | @@ -3245,26 +3237,24 @@ fn printErrMsgToFile( |
| 3245 | 3237 | try tree.renderError(parse_error, writer); |
| 3246 | 3238 | const text = text_buf.items; |
| 3247 | 3239 | |
| 3248 | | const stream = file.writer(); |
| 3249 | | try stream.print("{s}:{d}:{d}: error: {s}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text }); |
| 3240 | const message: Compilation.AllErrors.Message = .{ |
| 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 | }; |
| 3250 | 3250 | |
| 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 | }; |
| 3252 | 3256 | |
| 3253 | | // Print \r and \t as one space each so that column counts line up |
| 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 | | } |
| 3257 | message.renderToStdErr(ttyconf); |
| 3268 | 3258 | } |
| 3269 | 3259 | |
| 3270 | 3260 | pub const info_zen = |