mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-05-22 00:49:35 +03:00
zig fmt: implement Tree.lastToken() for all nodes
This commit is contained in:
committed by
Andrew Kelley
parent
515d4920e7
commit
4c8caf3343
+16
-6
@@ -538,6 +538,7 @@ pub const Tree = struct {
|
||||
.ArrayType,
|
||||
.SwitchCaseOne,
|
||||
.SwitchCase,
|
||||
.SwitchRange,
|
||||
=> n = datas[n].rhs,
|
||||
|
||||
.FieldAccess,
|
||||
@@ -580,8 +581,21 @@ pub const Tree = struct {
|
||||
}
|
||||
n = tree.extra_data[params.end - 1]; // last parameter
|
||||
},
|
||||
.CallComma, .AsyncCallComma => {
|
||||
end_offset += 2; // for the comma+rparen
|
||||
.TaggedUnionEnumTag => {
|
||||
const members = tree.extraData(datas[n].rhs, Node.SubRange);
|
||||
if (members.end - members.start == 0) {
|
||||
end_offset += 4; // for the rparen + rparen + lbrace + rbrace
|
||||
n = datas[n].lhs;
|
||||
} else {
|
||||
end_offset += 1; // for the rbrace
|
||||
n = tree.extra_data[members.end - 1]; // last parameter
|
||||
}
|
||||
},
|
||||
.CallComma,
|
||||
.AsyncCallComma,
|
||||
.TaggedUnionEnumTagComma,
|
||||
=> {
|
||||
end_offset += 2; // for the comma + rparen/rbrace
|
||||
const params = tree.extraData(datas[n].rhs, Node.SubRange);
|
||||
assert(params.end > params.start);
|
||||
n = tree.extra_data[params.end - 1]; // last parameter
|
||||
@@ -942,10 +956,6 @@ pub const Tree = struct {
|
||||
const extra = tree.extraData(datas[n].rhs, Node.ArrayTypeSentinel);
|
||||
n = extra.elem_type;
|
||||
},
|
||||
|
||||
.TaggedUnionEnumTag => unreachable, // TODO
|
||||
.TaggedUnionEnumTagComma => unreachable, // TODO
|
||||
.SwitchRange => unreachable, // TODO
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -841,6 +841,25 @@ test "zig fmt: tagged union with enum values" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: tagged union enum tag last token" {
|
||||
try testCanonical(
|
||||
\\test {
|
||||
\\ const U = union(enum(u32)) {};
|
||||
\\}
|
||||
\\
|
||||
\\test {
|
||||
\\ const U = union(enum(u32)) { foo };
|
||||
\\}
|
||||
\\
|
||||
\\test {
|
||||
\\ const U = union(enum(u32)) {
|
||||
\\ foo,
|
||||
\\ };
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: allowzero pointer" {
|
||||
try testCanonical(
|
||||
\\const T = [*]allowzero const u8;
|
||||
|
||||
Reference in New Issue
Block a user