authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-21 17:57:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-21 17:57:04-07:00
log79f18763679a9eac7cb1ff7bd9ede063277b266b
treee23e8897fba811277e6c80e4a7d28305a04c9ddf
parent2da2123128dfb78893109ad195fa536ff758f2ec

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.

2 files changed, 18 insertions(+), 17 deletions(-)

lib/std/zig/parse.zig+3-3
...@@ -66,9 +66,9 @@ pub fn parse(gpa: *Allocator, source: []const u8) Allocator.Error!Tree {...@@ -66,9 +66,9 @@ pub fn parse(gpa: *Allocator, source: []const u8) Allocator.Error!Tree {
66 });66 });
67 const root_members = try parser.parseContainerMembers();67 const root_members = try parser.parseContainerMembers();
68 const root_decls = try root_members.toSpan(&parser);68 const root_decls = try root_members.toSpan(&parser);
69 // parseContainerMembers will try to skip as much invalid tokens as69 if (parser.token_tags[parser.tok_i] != .eof) {
70 // it can, so we are now at EOF.70 try parser.warnExpected(.eof);
71 assert(parser.token_tags[parser.tok_i] == .eof);71 }
72 parser.nodes.items(.data)[0] = .{72 parser.nodes.items(.data)[0] = .{
73 .lhs = root_decls.start,73 .lhs = root_decls.start,
74 .rhs = root_decls.end,74 .rhs = root_decls.end,
lib/std/zig/parser_test.zig+15-14
...@@ -4187,20 +4187,21 @@ test "recovery: invalid container members" {...@@ -4187,20 +4187,21 @@ test "recovery: invalid container members" {
4187 });4187 });
4188}4188}
41894189
4190//test "recovery: extra '}' at top level" {4190// TODO after https://github.com/ziglang/zig/issues/35 is implemented,
4191// try testError(4191// we should be able to recover from this *at any indentation level*,
4192// \\}}}4192// reporting a parse error and yet also parsing all the decls even
4193// \\test "" {4193// inside structs.
4194// \\ a && b;4194test "recovery: extra '}' at top level" {
4195// \\}4195 try testError(
4196// , &[_]Error{4196 \\}}}
4197// .expected_container_members,4197 \\test "" {
4198// .expected_container_members,4198 \\ a && b;
4199// .expected_container_members,4199 \\}
4200// .invalid_and,4200 , &[_]Error{
4201// });4201 .expected_token,
4202//}4202 });
4203//4203}
4204
4204test "recovery: mismatched bracket at top level" {4205test "recovery: mismatched bracket at top level" {
4205 try testError(4206 try testError(
4206 \\const S = struct {4207 \\const S = struct {