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" {...@@ -1280,17 +1280,34 @@ test "zig fmt: async call in if condition" {
1280 );1280 );
1281}1281}
12821282
1283//test "zig fmt: 2nd arg multiline string" {1283test "zig fmt: 2nd arg multiline string" {
1284// try testCanonical(1284 try testCanonical(
1285// \\comptime {1285 \\comptime {
1286// \\ cases.addAsm("hello world linux x86_64",1286 \\ cases.addAsm("hello world linux x86_64",
1287// \\ \\.text1287 \\ \\.text
1288// \\ , "Hello, world!\n");1288 \\ , "Hello, world!\n");
1289// \\}1289 \\}
1290// \\1290 \\
1291// );1291 );
1292//}1292 try testTransform(
1293//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
1294//test "zig fmt: 2nd arg multiline string many args" {1311//test "zig fmt: 2nd arg multiline string many args" {
1295// try testCanonical(1312// try testCanonical(
1296// \\comptime {1313// \\comptime {
lib/std/zig/render.zig+17-8
...@@ -1879,23 +1879,23 @@ fn renderCall(...@@ -1879,23 +1879,23 @@ fn renderCall(
1879 const after_last_param_tok = tree.lastToken(last_param) + 1;1879 const after_last_param_tok = tree.lastToken(last_param) + 1;
1880 if (token_tags[after_last_param_tok] == .comma) {1880 if (token_tags[after_last_param_tok] == .comma) {
1881 ais.pushIndentNextLine();1881 ais.pushIndentNextLine();
1882 try renderToken(ais, tree, lparen, Space.newline); // (1882 try renderToken(ais, tree, lparen, .newline); // (
1883 for (params) |param_node, i| {1883 for (params) |param_node, i| {
1884 if (i + 1 < params.len) {1884 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 literals1887 // Unindent the comma for multiline string literals.
1888 const is_multiline_string = node_tags[param_node] == .multiline_string_literal;1888 const is_multiline_string = node_tags[param_node] == .multiline_string_literal;
1889 if (is_multiline_string) ais.popIndent();1889 if (is_multiline_string) ais.popIndent();
18901890
1891 const comma = tree.lastToken(param_node) + 1;1891 const comma = tree.lastToken(param_node) + 1;
1892 try renderToken(ais, tree, comma, Space.newline); // ,1892 try renderToken(ais, tree, comma, .newline); // ,
18931893
1894 if (is_multiline_string) ais.pushIndent();1894 if (is_multiline_string) ais.pushIndent();
18951895
1896 try renderExtraNewline(ais, tree, params[i + 1]);1896 try renderExtraNewline(ais, tree, params[i + 1]);
1897 } else {1897 } else {
1898 try renderExpression(ais, tree, param_node, Space.comma);1898 try renderExpression(ais, tree, param_node, .comma);
1899 }1899 }
1900 }1900 }
1901 ais.popIndent();1901 ais.popIndent();
...@@ -1903,14 +1903,23 @@ fn renderCall(...@@ -1903,14 +1903,23 @@ fn renderCall(
1903 }1903 }
19041904
1905 ais.pushIndentNextLine();1905 ais.pushIndentNextLine();
1906 try renderToken(ais, tree, lparen, Space.none); // (1906 try renderToken(ais, tree, lparen, .none); // (
19071907
1908 for (params) |param_node, i| {1908 for (params) |param_node, i| {
1909 try renderExpression(ais, tree, param_node, Space.none);1909 try renderExpression(ais, tree, param_node, .none);
19101910
1911 if (i + 1 < params.len) {1911 if (i + 1 < params.len) {
1912 const comma = tree.lastToken(param_node) + 1;1912 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 }
1914 }1923 }
1915 }1924 }
19161925