| author | |
| committer | |
| log | b48d354600406d39b29fe7327b09a62d2584a83f |
| tree | 6133c6ca43bc144308fa09e7a09e4a786b0a8c68 |
| parent | 37c6afa5b4c25e008206d8a036e02b7fd7189459 |
3 files changed, 35 insertions(+), 7 deletions(-)
std/segmented_list.zig+12-6| ... | ... | @@ -298,21 +298,27 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 298 | 298 | |
| 299 | 299 | return &it.list.dynamic_segments[it.shelf_index][it.box_index]; |
| 300 | 300 | } |
| 301 | ||
| 302 | pub fn set(it: &Iterator, index: usize) void { | |
| 303 | if (index < prealloc_item_count) { | |
| 304 | it.index = index; | |
| 305 | return; | |
| 306 | } | |
| 307 | it.shelf_index = shelfIndex(index); | |
| 308 | it.box_index = boxIndex(index, it.shelf_index); | |
| 309 | it.shelf_size = shelfSize(it.shelf_index); | |
| 310 | } | |
| 301 | 311 | }; |
| 302 | 312 | |
| 303 | 313 | pub fn iterator(self: &Self, start_index: usize) Iterator { |
| 304 | 314 | var it = Iterator { |
| 305 | 315 | .list = self, |
| 306 | .index = start_index, | |
| 316 | .index = undefined, | |
| 307 | 317 | .shelf_index = undefined, |
| 308 | 318 | .box_index = undefined, |
| 309 | 319 | .shelf_size = undefined, |
| 310 | 320 | }; |
| 311 | if (start_index >= prealloc_item_count) { | |
| 312 | it.shelf_index = shelfIndex(start_index); | |
| 313 | it.box_index = boxIndex(start_index, it.shelf_index); | |
| 314 | it.shelf_size = shelfSize(it.shelf_index); | |
| 315 | } | |
| 321 | it.set(start_index); | |
| 316 | 322 | return it; |
| 317 | 323 | } |
| 318 | 324 | }; |
std/zig/parse.zig+8-1| ... | ... | @@ -1017,7 +1017,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1017 | 1017 | continue; |
| 1018 | 1018 | }, |
| 1019 | 1019 | State.Else => |dest| { |
| 1020 | while (try eatLineComment(arena, &tok_it, &tree)) |_| { } | |
| 1020 | const old_index = tok_it.index; | |
| 1021 | var need_index_restore = false; | |
| 1022 | while (try eatLineComment(arena, &tok_it, &tree)) |_| { | |
| 1023 | need_index_restore = true; | |
| 1024 | } | |
| 1021 | 1025 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1022 | 1026 | const node = try arena.construct(ast.Node.Else { |
| 1023 | 1027 | .base = ast.Node {.id = ast.Node.Id.Else }, |
| ... | ... | @@ -1031,6 +1035,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1031 | 1035 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); |
| 1032 | 1036 | continue; |
| 1033 | 1037 | } else { |
| 1038 | if (need_index_restore) { | |
| 1039 | tok_it.set(old_index); | |
| 1040 | } | |
| 1034 | 1041 | continue; |
| 1035 | 1042 | } |
| 1036 | 1043 | }, |
std/zig/parser_test.zig+15| ... | ... | @@ -1,3 +1,18 @@ |
| 1 | test "zig fmt: comment after if before another if" { | |
| 2 | try testCanonical( | |
| 3 | \\test "aoeu" { | |
| 4 | \\ if (x) { | |
| 5 | \\ foo(); | |
| 6 | \\ } | |
| 7 | \\ // comment | |
| 8 | \\ if (x) { | |
| 9 | \\ bar(); | |
| 10 | \\ } | |
| 11 | \\} | |
| 12 | \\ | |
| 13 | ); | |
| 14 | } | |
| 15 | ||
| 1 | 16 | test "zig fmt: line comment between if block and else keyword" { |
| 2 | 17 | try testTransform( |
| 3 | 18 | \\test "aoeu" { |