cleanup
This commit is contained in:
@@ -14,7 +14,8 @@ pub const SourceLoc = struct {
|
||||
pub fn compute(source: []const u8, byte_offset: u32) SourceLoc {
|
||||
var line: u32 = 1;
|
||||
var col: u32 = 1;
|
||||
for (source[0..byte_offset]) |c| {
|
||||
const end = @min(byte_offset, @as(u32, @intCast(source.len)));
|
||||
for (source[0..end]) |c| {
|
||||
if (c == '\n') {
|
||||
line += 1;
|
||||
col = 1;
|
||||
@@ -93,4 +94,20 @@ pub const DiagnosticList = struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn renderDebug(self: *const DiagnosticList) void {
|
||||
for (self.items.items) |d| {
|
||||
const level_str = switch (d.level) {
|
||||
.err => "error",
|
||||
.warn => "warning",
|
||||
.note => "note",
|
||||
};
|
||||
if (d.span) |span| {
|
||||
const loc = SourceLoc.compute(self.source, span.start);
|
||||
std.debug.print("{s}:{d}:{d}: {s}: {s}\n", .{ self.file_name, loc.line, loc.col, level_str, d.message });
|
||||
} else {
|
||||
std.debug.print("{s}: {s}: {s}\n", .{ self.file_name, level_str, d.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user