authorgravatar for wxsychi@163.comriChar <wxsychi@163.com> 2022-09-02 17:52:33+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-09-02 12:52:33+03:00
log0d96f1f4fb3b217e11253c33e71973c3cbfb2f96
tree6980b30806c5a99442b80e4c3c012f8869bcb212
parent36f4f32fad3e88a84b6a10d78df31a4ed2c24465
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

zig fmt: remove trailing comma at the end of assembly clobber


2 files changed, 35 insertions(+), 3 deletions(-)

lib/std/zig/parser_test.zig+22
...@@ -16,6 +16,28 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {...@@ -16,6 +16,28 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {
16 );16 );
17}17}
1818
19test "zig fmt: remove trailing comma at the end of assembly clobber" {
20 try testTransform(
21 \\fn foo() void {
22 \\ asm volatile (""
23 \\ : [_] "" (-> type),
24 \\ :
25 \\ : "clobber1", "clobber2",
26 \\ );
27 \\}
28 \\
29 ,
30 \\fn foo() void {
31 \\ asm volatile (""
32 \\ : [_] "" (-> type),
33 \\ :
34 \\ : "clobber1", "clobber2"
35 \\ );
36 \\}
37 \\
38 );
39}
40
19test "zig fmt: respect line breaks in struct field value declaration" {41test "zig fmt: respect line breaks in struct field value declaration" {
20 try testCanonical(42 try testCanonical(
21 \\const Foo = struct {43 \\const Foo = struct {
lib/std/zig/render.zig+13-3
...@@ -2114,9 +2114,19 @@ fn renderAsm(...@@ -2114,9 +2114,19 @@ fn renderAsm(
2114 return renderToken(ais, tree, tok_i + 1, space);2114 return renderToken(ais, tree, tok_i + 1, space);
2115 },2115 },
2116 .comma => {2116 .comma => {
2117 try renderToken(ais, tree, tok_i, .none);2117 switch (token_tags[tok_i + 2]) {
2118 try renderToken(ais, tree, tok_i + 1, .space);2118 .r_paren => {
2119 tok_i += 2;2119 ais.setIndentDelta(indent_delta);
2120 ais.popIndent();
2121 try renderToken(ais, tree, tok_i, .newline);
2122 return renderToken(ais, tree, tok_i + 2, space);
2123 },
2124 else => {
2125 try renderToken(ais, tree, tok_i, .none);
2126 try renderToken(ais, tree, tok_i + 1, .space);
2127 tok_i += 2;
2128 },
2129 }
2120 },2130 },
2121 else => unreachable,2131 else => unreachable,
2122 }2132 }