forked from mirror/vulkan-zig
Add logs for std.zig.Ast.parse() failure
This commit is contained in:
@@ -118,6 +118,62 @@ pub const GenerateStep = struct {
|
|||||||
|
|
||||||
const src = out_buffer.items[0 .. out_buffer.items.len - 1 :0];
|
const src = out_buffer.items[0 .. out_buffer.items.len - 1 :0];
|
||||||
const tree = try std.zig.Ast.parse(b.allocator, src, .zig);
|
const tree = try std.zig.Ast.parse(b.allocator, src, .zig);
|
||||||
|
|
||||||
|
if (tree.errors.len > 0) {
|
||||||
|
var start: usize = undefined;
|
||||||
|
var end: usize = undefined;
|
||||||
|
var index: usize = undefined;
|
||||||
|
var repeat: usize = undefined;
|
||||||
|
var spaces: [] const u8 = undefined;
|
||||||
|
var carets: [] const u8 = undefined;
|
||||||
|
var current_token: std.zig.Token = undefined;
|
||||||
|
|
||||||
|
std.debug.print("{s}\n", .{ src, });
|
||||||
|
|
||||||
|
var tokens = try std.ArrayList (std.zig.Ast.Error).initCapacity(b.allocator, tree.errors.len);
|
||||||
|
try tokens.appendSlice(tree.errors);
|
||||||
|
|
||||||
|
std.mem.sort(std.zig.Ast.Error, tokens.items, {},
|
||||||
|
struct {
|
||||||
|
pub fn desc(_: void, l_err: std.zig.Ast.Error, r_err: std.zig.Ast.Error) bool {
|
||||||
|
return l_err.token > r_err.token;
|
||||||
|
}
|
||||||
|
}.desc);
|
||||||
|
|
||||||
|
var iterator = std.zig.Tokenizer.init(src);
|
||||||
|
|
||||||
|
index = 1;
|
||||||
|
current_token = iterator.next();
|
||||||
|
|
||||||
|
while (current_token.tag != std.zig.Token.Tag.eof and tokens.items.len > 0) {
|
||||||
|
if (tokens.items[tokens.items.len - 1].token == index) {
|
||||||
|
start = std.mem.lastIndexOf(u8, src[0..current_token.loc.start], "\n") orelse 0;
|
||||||
|
end = (std.mem.indexOf(u8, src[current_token.loc.end..], "\n") orelse src.len - current_token.loc.end) + current_token.loc.end;
|
||||||
|
|
||||||
|
repeat = 1;
|
||||||
|
spaces = "";
|
||||||
|
while (repeat < current_token.loc.start - start) {
|
||||||
|
spaces = try std.fmt.allocPrint(b.allocator, "{s} ", .{ spaces, });
|
||||||
|
repeat += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat = 1;
|
||||||
|
carets = "";
|
||||||
|
while (repeat < current_token.loc.end + 1 - current_token.loc.start) {
|
||||||
|
carets = try std.fmt.allocPrint(b.allocator, "{s}^", .{ carets, });
|
||||||
|
repeat += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std.debug.print("ERROR: {}\nTOKEN: {}\n\n{s}\n{s}{s}\n", .{ tokens.items[tokens.items.len - 1], current_token, if(src[start] == '\n') src[start + 1..end] else src[start..end], spaces, carets, });
|
||||||
|
|
||||||
|
_ = tokens.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
current_token = iterator.next();
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std.debug.assert(tree.errors.len == 0); // If this triggers, vulkan-zig produced invalid code.
|
std.debug.assert(tree.errors.len == 0); // If this triggers, vulkan-zig produced invalid code.
|
||||||
|
|
||||||
const formatted = try tree.render(b.allocator);
|
const formatted = try tree.render(b.allocator);
|
||||||
|
|||||||
Reference in New Issue
Block a user