zig fmt: fix whitespace

closes #2819
closes #2825
This commit is contained in:
Andrew Kelley 2019-07-05 14:46:21 -04:00
parent 5b42c76951
commit 4f43a4b30f
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 22 additions and 23 deletions

View File

@ -375,28 +375,21 @@ fn printErrMsgToFile(
const text = text_buf.toOwnedSlice();
const stream = &file.outStream().stream;
if (!color_on) {
try stream.print(
"{}:{}:{}: error: {}\n",
path,
start_loc.line + 1,
start_loc.column + 1,
text,
);
return;
}
try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
try stream.print(
"{}:{}:{}: error: {}\n{}\n",
path,
start_loc.line + 1,
start_loc.column + 1,
text,
tree.source[start_loc.line_start..start_loc.line_end],
);
if (!color_on) return;
// Print \r and \t as one space each so that column counts line up
for (tree.source[start_loc.line_start..start_loc.line_end]) |byte| {
try stream.writeByte(switch (byte) {
'\r', '\t' => ' ',
else => byte,
});
}
try stream.writeByte('\n');
try stream.writeByteNTimes(' ', start_loc.column);
try stream.writeByteNTimes('~', last_token.end - first_token.start);
try stream.write("\n");
try stream.writeByte('\n');
}
export fn stage2_DepTokenizer_init(input: [*]const u8, len: usize) stage2_DepTokenizer {

View File

@ -8,6 +8,15 @@ test "zig fmt: change use to usingnamespace" {
);
}
test "zig fmt: whitespace fixes" {
try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}",
\\test "" {
\\ const hi = x;
\\}
\\
);
}
test "zig fmt: while else err prong with no block" {
try testCanonical(
\\test "" {

View File

@ -301,10 +301,7 @@ pub const Tokenizer = struct {
const c = self.buffer[self.index];
switch (state) {
State.Start => switch (c) {
' ' => {
result.start = self.index + 1;
},
'\n' => {
' ', '\n', '\t', '\r' => {
result.start = self.index + 1;
},
'c' => {