zig fmt: fix comment after if before another if
This commit is contained in:
parent
37c6afa5b4
commit
b48d354600
@ -298,21 +298,27 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
|
|||||||
|
|
||||||
return &it.list.dynamic_segments[it.shelf_index][it.box_index];
|
return &it.list.dynamic_segments[it.shelf_index][it.box_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set(it: &Iterator, index: usize) void {
|
||||||
|
if (index < prealloc_item_count) {
|
||||||
|
it.index = index;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
it.shelf_index = shelfIndex(index);
|
||||||
|
it.box_index = boxIndex(index, it.shelf_index);
|
||||||
|
it.shelf_size = shelfSize(it.shelf_index);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn iterator(self: &Self, start_index: usize) Iterator {
|
pub fn iterator(self: &Self, start_index: usize) Iterator {
|
||||||
var it = Iterator {
|
var it = Iterator {
|
||||||
.list = self,
|
.list = self,
|
||||||
.index = start_index,
|
.index = undefined,
|
||||||
.shelf_index = undefined,
|
.shelf_index = undefined,
|
||||||
.box_index = undefined,
|
.box_index = undefined,
|
||||||
.shelf_size = undefined,
|
.shelf_size = undefined,
|
||||||
};
|
};
|
||||||
if (start_index >= prealloc_item_count) {
|
it.set(start_index);
|
||||||
it.shelf_index = shelfIndex(start_index);
|
|
||||||
it.box_index = boxIndex(start_index, it.shelf_index);
|
|
||||||
it.shelf_size = shelfSize(it.shelf_index);
|
|
||||||
}
|
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1017,7 +1017,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
State.Else => |dest| {
|
State.Else => |dest| {
|
||||||
while (try eatLineComment(arena, &tok_it, &tree)) |_| { }
|
const old_index = tok_it.index;
|
||||||
|
var need_index_restore = false;
|
||||||
|
while (try eatLineComment(arena, &tok_it, &tree)) |_| {
|
||||||
|
need_index_restore = true;
|
||||||
|
}
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
|
||||||
const node = try arena.construct(ast.Node.Else {
|
const node = try arena.construct(ast.Node.Else {
|
||||||
.base = ast.Node {.id = ast.Node.Id.Else },
|
.base = ast.Node {.id = ast.Node.Id.Else },
|
||||||
@ -1031,6 +1035,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
|
try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
if (need_index_restore) {
|
||||||
|
tok_it.set(old_index);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
test "zig fmt: comment after if before another if" {
|
||||||
|
try testCanonical(
|
||||||
|
\\test "aoeu" {
|
||||||
|
\\ if (x) {
|
||||||
|
\\ foo();
|
||||||
|
\\ }
|
||||||
|
\\ // comment
|
||||||
|
\\ if (x) {
|
||||||
|
\\ bar();
|
||||||
|
\\ }
|
||||||
|
\\}
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
test "zig fmt: line comment between if block and else keyword" {
|
test "zig fmt: line comment between if block and else keyword" {
|
||||||
try testTransform(
|
try testTransform(
|
||||||
\\test "aoeu" {
|
\\test "aoeu" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user