authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-10 16:35:37+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-10 11:53:53-08:00
log3110a73486223aba9152946fa0184536fc3c4b76
tree4ca164206981ac1faae8002dfbfa10aa904ad076
parent8c4f3e5a319b2c700a57d833e1aaf01e769f8d4a

zig fmt: implement Tree.lastToken() for array types


2 files changed, 18 insertions(+), 2 deletions(-)

lib/std/zig/ast.zig+5-2
......@@ -529,6 +529,7 @@ pub const Tree = struct {
529529 .PtrTypeSentinel,
530530 .PtrType,
531531 .PtrTypeBitRange,
532 .ArrayType,
532533 .SwitchCaseOne,
533534 .SwitchCase,
534535 => n = datas[n].rhs,
......@@ -902,6 +903,10 @@ pub const Tree = struct {
902903 return main_tokens[n] + end_offset;
903904 }
904905 },
906 .ArrayTypeSentinel => {
907 const extra = tree.extraData(datas[n].rhs, Node.ArrayTypeSentinel);
908 n = extra.elem_type;
909 },
905910
906911 // These are not supported by lastToken() because implementation would
907912 // require recursion due to the optional comma followed by rbrace.
......@@ -917,8 +922,6 @@ pub const Tree = struct {
917922 .TaggedUnionEnumTag => unreachable, // TODO
918923 .TaggedUnionEnumTagComma => unreachable, // TODO
919924 .SwitchRange => unreachable, // TODO
920 .ArrayType => unreachable, // TODO
921 .ArrayTypeSentinel => unreachable, // TODO
922925 };
923926 }
924927
lib/std/zig/parser_test.zig+13
......@@ -353,6 +353,19 @@ test "zig fmt: anytype struct field" {
353353 );
354354}
355355
356test "zig fmt: array types last token" {
357 try testCanonical(
358 \\test {
359 \\ const x = [40]u32;
360 \\}
361 \\
362 \\test {
363 \\ const x = [40:0]u32;
364 \\}
365 \\
366 );
367}
368
356369//test "zig fmt: sentinel-terminated array type" {
357370// try testCanonical(
358371// \\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {