authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 16:00:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 16:00:21-07:00
log253906fb93f25481ae80af9043b58342858e156c
tree5f1ac5ce0460d45b0c14a6a507fccbfdabef2657
parent45634851de92f7848b648a0e009247e7f102e9ff

zig fmt: 2nd arg multiline string


2 files changed, 45 insertions(+), 19 deletions(-)

lib/std/zig/parser_test.zig+28-11
......@@ -1280,17 +1280,34 @@ test "zig fmt: async call in if condition" {
12801280 );
12811281}
12821282
1283//test "zig fmt: 2nd arg multiline string" {
1284// try testCanonical(
1285// \\comptime {
1286// \\ cases.addAsm("hello world linux x86_64",
1287// \\ \\.text
1288// \\ , "Hello, world!\n");
1289// \\}
1290// \\
1291// );
1292//}
1293//
1283test "zig fmt: 2nd arg multiline string" {
1284 try testCanonical(
1285 \\comptime {
1286 \\ cases.addAsm("hello world linux x86_64",
1287 \\ \\.text
1288 \\ , "Hello, world!\n");
1289 \\}
1290 \\
1291 );
1292 try testTransform(
1293 \\comptime {
1294 \\ cases.addAsm("hello world linux x86_64",
1295 \\ \\.text
1296 \\ , "Hello, world!\n",);
1297 \\}
1298 ,
1299 \\comptime {
1300 \\ cases.addAsm(
1301 \\ "hello world linux x86_64",
1302 \\ \\.text
1303 \\ ,
1304 \\ "Hello, world!\n",
1305 \\ );
1306 \\}
1307 \\
1308 );
1309}
1310
12941311//test "zig fmt: 2nd arg multiline string many args" {
12951312// try testCanonical(
12961313// \\comptime {
lib/std/zig/render.zig+17-8
......@@ -1879,23 +1879,23 @@ fn renderCall(
18791879 const after_last_param_tok = tree.lastToken(last_param) + 1;
18801880 if (token_tags[after_last_param_tok] == .comma) {
18811881 ais.pushIndentNextLine();
1882 try renderToken(ais, tree, lparen, Space.newline); // (
1882 try renderToken(ais, tree, lparen, .newline); // (
18831883 for (params) |param_node, i| {
18841884 if (i + 1 < params.len) {
1885 try renderExpression(ais, tree, param_node, Space.none);
1885 try renderExpression(ais, tree, param_node, .none);
18861886
1887 // Unindent the comma for multiline string literals
1887 // Unindent the comma for multiline string literals.
18881888 const is_multiline_string = node_tags[param_node] == .multiline_string_literal;
18891889 if (is_multiline_string) ais.popIndent();
18901890
18911891 const comma = tree.lastToken(param_node) + 1;
1892 try renderToken(ais, tree, comma, Space.newline); // ,
1892 try renderToken(ais, tree, comma, .newline); // ,
18931893
18941894 if (is_multiline_string) ais.pushIndent();
18951895
18961896 try renderExtraNewline(ais, tree, params[i + 1]);
18971897 } else {
1898 try renderExpression(ais, tree, param_node, Space.comma);
1898 try renderExpression(ais, tree, param_node, .comma);
18991899 }
19001900 }
19011901 ais.popIndent();
......@@ -1903,14 +1903,23 @@ fn renderCall(
19031903 }
19041904
19051905 ais.pushIndentNextLine();
1906 try renderToken(ais, tree, lparen, Space.none); // (
1906 try renderToken(ais, tree, lparen, .none); // (
19071907
19081908 for (params) |param_node, i| {
1909 try renderExpression(ais, tree, param_node, Space.none);
1909 try renderExpression(ais, tree, param_node, .none);
19101910
19111911 if (i + 1 < params.len) {
19121912 const comma = tree.lastToken(param_node) + 1;
1913 try renderToken(ais, tree, comma, Space.space);
1913 const this_multiline_string = node_tags[param_node] == .multiline_string_literal;
1914 const next_multiline_string = node_tags[params[i + 1]] == .multiline_string_literal;
1915 const comma_space: Space = if (next_multiline_string) .none else .space;
1916 if (this_multiline_string) {
1917 ais.popIndent();
1918 try renderToken(ais, tree, comma, comma_space);
1919 ais.pushIndent();
1920 } else {
1921 try renderToken(ais, tree, comma, comma_space);
1922 }
19141923 }
19151924 }
19161925