zig fmt: better multiline string handling

This commit is contained in:
Andrew Kelley 2018-04-30 15:10:55 -04:00
parent e14db23661
commit 47680cc0d8
2 changed files with 14 additions and 5 deletions

View File

@ -3512,7 +3512,8 @@ pub const Parser = struct {
try stack.append(RenderState { .Text = ";" });
if (var_decl.init_node) |init_node| {
try stack.append(RenderState { .Expression = init_node });
try stack.append(RenderState { .Text = " = " });
const text = if (init_node.id == ast.Node.Id.MultilineStringLiteral) " =" else " = ";
try stack.append(RenderState { .Text = text });
}
if (var_decl.align_node) |align_node| {
try stack.append(RenderState { .Text = ")" });
@ -4063,7 +4064,7 @@ pub const Parser = struct {
try stream.writeByteNTimes(' ', indent + indent_delta);
try stream.print("{}", self.tokenizer.getTokenSlice(t));
}
try stream.writeByteNTimes(' ', indent + indent_delta);
try stream.writeByteNTimes(' ', indent);
},
ast.Node.Id.UndefinedLiteral => {
const undefined_literal = @fieldParentPtr(ast.Node.UndefinedLiteral, "base", base);

View File

@ -423,10 +423,18 @@ test "zig fmt: functions" {
test "zig fmt: multiline string" {
try testCanonical(
\\const s =
\\ \\ something
\\ \\ something else
\\test "" {
\\ const s1 =
\\ \\one
\\ \\two)
\\ \\three
\\ ;
\\ const s2 =
\\ c\\one
\\ c\\two)
\\ c\\three
\\ ;
\\}
\\
);
}