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 {...@@ -529,6 +529,7 @@ pub const Tree = struct {
529 .PtrTypeSentinel,529 .PtrTypeSentinel,
530 .PtrType,530 .PtrType,
531 .PtrTypeBitRange,531 .PtrTypeBitRange,
532 .ArrayType,
532 .SwitchCaseOne,533 .SwitchCaseOne,
533 .SwitchCase,534 .SwitchCase,
534 => n = datas[n].rhs,535 => n = datas[n].rhs,
...@@ -902,6 +903,10 @@ pub const Tree = struct {...@@ -902,6 +903,10 @@ pub const Tree = struct {
902 return main_tokens[n] + end_offset;903 return main_tokens[n] + end_offset;
903 }904 }
904 },905 },
906 .ArrayTypeSentinel => {
907 const extra = tree.extraData(datas[n].rhs, Node.ArrayTypeSentinel);
908 n = extra.elem_type;
909 },
905910
906 // These are not supported by lastToken() because implementation would911 // These are not supported by lastToken() because implementation would
907 // require recursion due to the optional comma followed by rbrace.912 // require recursion due to the optional comma followed by rbrace.
...@@ -917,8 +922,6 @@ pub const Tree = struct {...@@ -917,8 +922,6 @@ pub const Tree = struct {
917 .TaggedUnionEnumTag => unreachable, // TODO922 .TaggedUnionEnumTag => unreachable, // TODO
918 .TaggedUnionEnumTagComma => unreachable, // TODO923 .TaggedUnionEnumTagComma => unreachable, // TODO
919 .SwitchRange => unreachable, // TODO924 .SwitchRange => unreachable, // TODO
920 .ArrayType => unreachable, // TODO
921 .ArrayTypeSentinel => unreachable, // TODO
922 };925 };
923 }926 }
924927
lib/std/zig/parser_test.zig+13
...@@ -353,6 +353,19 @@ test "zig fmt: anytype struct field" {...@@ -353,6 +353,19 @@ test "zig fmt: anytype struct field" {
353 );353 );
354}354}
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
356//test "zig fmt: sentinel-terminated array type" {369//test "zig fmt: sentinel-terminated array type" {
357// try testCanonical(370// try testCanonical(
358// \\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {371// \\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {