| author | |
| committer | |
| log | 2a3f3766a437faed13736c1ff505854b6737ae33 |
| tree | 1c3756e7be1b39cb7d02083a1f29b7aa2a11cb42 |
| parent | 5d22204d2dbf686d8b827eca15253914ef9543ab |
3 files changed, 33 insertions(+), 60 deletions(-)
lib/std/zig/parse.zig+3-2| ... | ... | @@ -178,7 +178,6 @@ const Parser = struct { |
| 178 | 178 | .expected_block_or_assignment, |
| 179 | 179 | .expected_block_or_expr, |
| 180 | 180 | .expected_block_or_field, |
| 181 | .expected_container_members, | |
| 182 | 181 | .expected_expr, |
| 183 | 182 | .expected_expr_or_assignment, |
| 184 | 183 | .expected_fn, |
| ... | ... | @@ -401,10 +400,12 @@ const Parser = struct { |
| 401 | 400 | }); |
| 402 | 401 | try p.warnMsg(.{ |
| 403 | 402 | .tag = .previous_field, |
| 403 | .is_note = true, | |
| 404 | 404 | .token = last_field, |
| 405 | 405 | }); |
| 406 | 406 | try p.warnMsg(.{ |
| 407 | 407 | .tag = .next_field, |
| 408 | .is_note = true, | |
| 408 | 409 | .token = identifier, |
| 409 | 410 | }); |
| 410 | 411 | // Continue parsing; error will be reported later. |
| ... | ... | @@ -985,7 +986,7 @@ const Parser = struct { |
| 985 | 986 | .keyword_switch => return p.expectSwitchExpr(), |
| 986 | 987 | .keyword_if => return p.expectIfStatement(), |
| 987 | 988 | .keyword_enum, .keyword_struct, .keyword_union => { |
| 988 | const identifier = p.tok_i + 2; | |
| 989 | const identifier = p.tok_i + 1; | |
| 989 | 990 | if (try p.parseCStyleContainer()) { |
| 990 | 991 | // Return something so that `expectStatement` is happy. |
| 991 | 992 | return p.addNode(.{ |
src/Module.zig+15-20| ... | ... | @@ -3324,26 +3324,21 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 3324 | 3324 | .parent_decl_node = 0, |
| 3325 | 3325 | .lazy = .{ .byte_abs = byte_abs }, |
| 3326 | 3326 | }, err_msg, "invalid byte: '{'}'", .{std.zig.fmtEscapes(source[byte_abs..][0..1])}); |
| 3327 | } else if (parse_err.tag == .decl_between_fields) { | |
| 3328 | try mod.errNoteNonLazy(.{ | |
| 3329 | .file_scope = file, | |
| 3330 | .parent_decl_node = 0, | |
| 3331 | .lazy = .{ .byte_abs = token_starts[file.tree.errors[1].token] }, | |
| 3332 | }, err_msg, "field before declarations here", .{}); | |
| 3333 | try mod.errNoteNonLazy(.{ | |
| 3334 | .file_scope = file, | |
| 3335 | .parent_decl_node = 0, | |
| 3336 | .lazy = .{ .byte_abs = token_starts[file.tree.errors[2].token] }, | |
| 3337 | }, err_msg, "field after declarations here", .{}); | |
| 3338 | } else if (parse_err.tag == .c_style_container) { | |
| 3339 | const note = file.tree.errors[1]; | |
| 3340 | try mod.errNoteNonLazy(.{ | |
| 3341 | .file_scope = file, | |
| 3342 | .parent_decl_node = 0, | |
| 3343 | .lazy = .{ .byte_abs = token_starts[note.token] }, | |
| 3344 | }, err_msg, "to declare a container do 'const {s} = {s}'", .{ | |
| 3345 | file.tree.tokenSlice(note.token), note.extra.expected_tag.symbol(), | |
| 3346 | }); | |
| 3327 | } | |
| 3328 | ||
| 3329 | for (file.tree.errors[1..]) |note| { | |
| 3330 | if (!note.is_note) break; | |
| 3331 | ||
| 3332 | try file.tree.renderError(note, msg.writer()); | |
| 3333 | err_msg.notes = try mod.gpa.realloc(err_msg.notes, err_msg.notes.len + 1); | |
| 3334 | err_msg.notes[err_msg.notes.len - 1] = .{ | |
| 3335 | .src_loc = .{ | |
| 3336 | .file_scope = file, | |
| 3337 | .parent_decl_node = 0, | |
| 3338 | .lazy = .{ .byte_abs = token_starts[note.token] }, | |
| 3339 | }, | |
| 3340 | .msg = msg.toOwnedSlice(), | |
| 3341 | }; | |
| 3347 | 3342 | } |
| 3348 | 3343 | |
| 3349 | 3344 | { |
src/main.zig+15-38| ... | ... | @@ -4367,7 +4367,7 @@ fn printErrsMsgToStdErr( |
| 4367 | 4367 | defer text_buf.deinit(); |
| 4368 | 4368 | const writer = text_buf.writer(); |
| 4369 | 4369 | try tree.renderError(parse_error, writer); |
| 4370 | const text = text_buf.items; | |
| 4370 | const text = try arena.dupe(u8, text_buf.items); | |
| 4371 | 4371 | |
| 4372 | 4372 | var notes_buffer: [2]Compilation.AllErrors.Message = undefined; |
| 4373 | 4373 | var notes_len: usize = 0; |
| ... | ... | @@ -4388,49 +4388,26 @@ fn printErrsMsgToStdErr( |
| 4388 | 4388 | }, |
| 4389 | 4389 | }; |
| 4390 | 4390 | notes_len += 1; |
| 4391 | } else if (parse_error.tag == .decl_between_fields) { | |
| 4392 | const prev_loc = tree.tokenLocation(0, parse_errors[i + 1].token); | |
| 4393 | notes_buffer[0] = .{ | |
| 4394 | .src = .{ | |
| 4395 | .src_path = path, | |
| 4396 | .msg = "field before declarations here", | |
| 4397 | .byte_offset = @intCast(u32, prev_loc.line_start), | |
| 4398 | .line = @intCast(u32, prev_loc.line), | |
| 4399 | .column = @intCast(u32, prev_loc.column), | |
| 4400 | .source_line = tree.source[prev_loc.line_start..prev_loc.line_end], | |
| 4401 | }, | |
| 4402 | }; | |
| 4403 | const next_loc = tree.tokenLocation(0, parse_errors[i + 2].token); | |
| 4404 | notes_buffer[1] = .{ | |
| 4405 | .src = .{ | |
| 4406 | .src_path = path, | |
| 4407 | .msg = "field after declarations here", | |
| 4408 | .byte_offset = @intCast(u32, next_loc.line_start), | |
| 4409 | .line = @intCast(u32, next_loc.line), | |
| 4410 | .column = @intCast(u32, next_loc.column), | |
| 4411 | .source_line = tree.source[next_loc.line_start..next_loc.line_end], | |
| 4412 | }, | |
| 4413 | }; | |
| 4414 | notes_len = 2; | |
| 4415 | i += 2; | |
| 4416 | } else if (parse_error.tag == .c_style_container) { | |
| 4417 | const note = tree.errors[i + 1]; | |
| 4391 | } | |
| 4392 | ||
| 4393 | for (parse_errors[i + 1 ..]) |note| { | |
| 4394 | if (!note.is_note) break; | |
| 4418 | 4395 | |
| 4419 | const prev_loc = tree.tokenLocation(0, parse_errors[i + 1].token); | |
| 4420 | notes_buffer[0] = .{ | |
| 4396 | text_buf.items.len = 0; | |
| 4397 | try tree.renderError(note, writer); | |
| 4398 | const note_loc = tree.tokenLocation(0, note.token); | |
| 4399 | notes_buffer[notes_len] = .{ | |
| 4421 | 4400 | .src = .{ |
| 4422 | 4401 | .src_path = path, |
| 4423 | .msg = try std.fmt.allocPrint(arena, "to declare a container do 'const {s} = {s}'", .{ | |
| 4424 | tree.tokenSlice(note.token), note.extra.expected_tag.symbol(), | |
| 4425 | }), | |
| 4426 | .byte_offset = @intCast(u32, prev_loc.line_start), | |
| 4427 | .line = @intCast(u32, prev_loc.line), | |
| 4428 | .column = @intCast(u32, prev_loc.column), | |
| 4429 | .source_line = tree.source[prev_loc.line_start..prev_loc.line_end], | |
| 4402 | .msg = try arena.dupe(u8, text_buf.items), | |
| 4403 | .byte_offset = @intCast(u32, note_loc.line_start), | |
| 4404 | .line = @intCast(u32, note_loc.line), | |
| 4405 | .column = @intCast(u32, note_loc.column), | |
| 4406 | .source_line = tree.source[note_loc.line_start..note_loc.line_end], | |
| 4430 | 4407 | }, |
| 4431 | 4408 | }; |
| 4432 | notes_len = 1; | |
| 4433 | 4409 | i += 1; |
| 4410 | notes_len += 1; | |
| 4434 | 4411 | } |
| 4435 | 4412 | |
| 4436 | 4413 | const extra_offset = tree.errorOffset(parse_error); |