parser: remove support for recovering from extra top level end curlies

After #35 is implemented,
we should be able to recover from this *at any indentation level*,
reporting a parse error and yet also parsing all the decls even
inside structs. Until then, I don't want to add any hacks to make
this work.
This commit is contained in:
Andrew Kelley
2021-02-21 17:57:04 -07:00
parent 2da2123128
commit 79f1876367
2 changed files with 18 additions and 17 deletions

View File

@@ -66,9 +66,9 @@ pub fn parse(gpa: *Allocator, source: []const u8) Allocator.Error!Tree {
});
const root_members = try parser.parseContainerMembers();
const root_decls = try root_members.toSpan(&parser);
// parseContainerMembers will try to skip as much invalid tokens as
// it can, so we are now at EOF.
assert(parser.token_tags[parser.tok_i] == .eof);
if (parser.token_tags[parser.tok_i] != .eof) {
try parser.warnExpected(.eof);
}
parser.nodes.items(.data)[0] = .{
.lhs = root_decls.start,
.rhs = root_decls.end,

View File

@@ -4187,20 +4187,21 @@ test "recovery: invalid container members" {
});
}
//test "recovery: extra '}' at top level" {
// try testError(
// \\}}}
// \\test "" {
// \\ a && b;
// \\}
// , &[_]Error{
// .expected_container_members,
// .expected_container_members,
// .expected_container_members,
// .invalid_and,
// });
//}
//
// TODO after https://github.com/ziglang/zig/issues/35 is implemented,
// we should be able to recover from this *at any indentation level*,
// reporting a parse error and yet also parsing all the decls even
// inside structs.
test "recovery: extra '}' at top level" {
try testError(
\\}}}
\\test "" {
\\ a && b;
\\}
, &[_]Error{
.expected_token,
});
}
test "recovery: mismatched bracket at top level" {
try testError(
\\const S = struct {