Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error printing on invalid codegen #8

Open
clickingbuttons opened this issue Jun 15, 2023 · 1 comment
Open

Add error printing on invalid codegen #8

clickingbuttons opened this issue Jun 15, 2023 · 1 comment

Comments

@clickingbuttons
Copy link

Useful for when Zig breaks codegenned syntax and for codegen devs. Here's one way to do it:

fn format(allocator: Allocator, fname: []const u8, code: [:0]const u8) ![]const u8 {
    var ast = try std.zig.Ast.parse(allocator, code, .zig);
    defer ast.deinit(allocator);

    if (ast.errors.len > 0) {
        for (ast.errors) |err| {
            var buf = std.ArrayList(u8).init(allocator);
            defer buf.deinit();
            ast.renderError(err, buf.writer()) catch {};
            log.err("formatting {s}: {s}", .{ fname, buf.items });
        }
        return code;
    }

    return try ast.render(allocator);
}
@travisstaloch
Copy link
Owner

partially addressed in 0a7d9d4

i don't consider this complete as the error message doesn't show any of the generated code which caused the error. as-is it only shows the parse error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants