| author | |
| committer | |
| log | 79f18763679a9eac7cb1ff7bd9ede063277b266b |
| tree | e23e8897fba811277e6c80e4a7d28305a04c9ddf |
| parent | 2da2123128dfb78893109ad195fa536ff758f2ec |
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 as | 69 | 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 | } |
| 4189 | 4189 | ||
| 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; | 4194 | test "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 | |||
| 4204 | test "recovery: mismatched bracket at top level" { | 4205 | test "recovery: mismatched bracket at top level" { |
| 4205 | try testError( | 4206 | try testError( |
| 4206 | \\const S = struct { | 4207 | \\const S = struct { |