mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 21:38:33 +00:00
zig fmt: implement Tree.lastToken() for array types
This commit is contained in:
parent
8c4f3e5a31
commit
3110a73486
@ -529,6 +529,7 @@ pub const Tree = struct {
|
||||
.PtrTypeSentinel,
|
||||
.PtrType,
|
||||
.PtrTypeBitRange,
|
||||
.ArrayType,
|
||||
.SwitchCaseOne,
|
||||
.SwitchCase,
|
||||
=> n = datas[n].rhs,
|
||||
@ -902,6 +903,10 @@ pub const Tree = struct {
|
||||
return main_tokens[n] + end_offset;
|
||||
}
|
||||
},
|
||||
.ArrayTypeSentinel => {
|
||||
const extra = tree.extraData(datas[n].rhs, Node.ArrayTypeSentinel);
|
||||
n = extra.elem_type;
|
||||
},
|
||||
|
||||
// These are not supported by lastToken() because implementation would
|
||||
// require recursion due to the optional comma followed by rbrace.
|
||||
@ -917,8 +922,6 @@ pub const Tree = struct {
|
||||
.TaggedUnionEnumTag => unreachable, // TODO
|
||||
.TaggedUnionEnumTagComma => unreachable, // TODO
|
||||
.SwitchRange => unreachable, // TODO
|
||||
.ArrayType => unreachable, // TODO
|
||||
.ArrayTypeSentinel => unreachable, // TODO
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -353,6 +353,19 @@ test "zig fmt: anytype struct field" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: array types last token" {
|
||||
try testCanonical(
|
||||
\\test {
|
||||
\\ const x = [40]u32;
|
||||
\\}
|
||||
\\
|
||||
\\test {
|
||||
\\ const x = [40:0]u32;
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
//test "zig fmt: sentinel-terminated array type" {
|
||||
// try testCanonical(
|
||||
// \\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user