Give a helpful error message for those transitioning from C's 'struct Foo {};' to Zig's 'const Foo = struct {};'.
fn parseCStyleContainer(p: *Parse) Error!bool
fn parseCStyleContainer(p: *Parse) Error!bool {
if (!p.recover) return false;
const main_token = p.tok_i;
switch (p.tokenTag(p.tok_i)) {
.keyword_enum, .keyword_union, .keyword_struct => {},
else => return false,
}
const identifier = p.tok_i + 1;
if (p.tokenTag(identifier) != .identifier) return false;
p.tok_i += 2;
try p.warnMsg(.{
.tag = .c_style_container,
.token = identifier,
.extra = .{ .expected_tag = p.tokenTag(main_token) },
});
try p.warnMsg(.{
.tag = .zig_style_container,
.is_note = true,
.token = identifier,
.extra = .{ .expected_tag = p.tokenTag(main_token) },
});
_ = try p.expectToken(.l_brace);
_ = try p.parseContainerMembers();
_ = try p.expectToken(.r_brace);
try p.expectSemicolon(.expected_semi_after_decl, true);
return true;
}