authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-05 14:46:21-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-05 14:46:21-04:00
log4f43a4b30f8a6dad7a9a35ccf1cef89b6d239997
tree08f296237b8fd4b75ab48d23f62ae2433849cd7a
parent5b42c7695183b2b529a1ce119f9b76de09f728df
signaturelock-open Commit is signed but in an unrecognized format.

zig fmt: fix whitespace

closes #2819 closes #2825

3 files changed, 22 insertions(+), 23 deletions(-)

src-self-hosted/stage1.zig+12-19
......@@ -375,28 +375,21 @@ fn printErrMsgToFile(
375375 const text = text_buf.toOwnedSlice();
376376
377377 const stream = &file.outStream().stream;
378 if (!color_on) {
379 try stream.print(
380 "{}:{}:{}: error: {}\n",
381 path,
382 start_loc.line + 1,
383 start_loc.column + 1,
384 text,
385 );
386 return;
387 }
378 try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
388379
389 try stream.print(
390 "{}:{}:{}: error: {}\n{}\n",
391 path,
392 start_loc.line + 1,
393 start_loc.column + 1,
394 text,
395 tree.source[start_loc.line_start..start_loc.line_end],
396 );
380 if (!color_on) return;
381
382 // Print \r and \t as one space each so that column counts line up
383 for (tree.source[start_loc.line_start..start_loc.line_end]) |byte| {
384 try stream.writeByte(switch (byte) {
385 '\r', '\t' => ' ',
386 else => byte,
387 });
388 }
389 try stream.writeByte('\n');
397390 try stream.writeByteNTimes(' ', start_loc.column);
398391 try stream.writeByteNTimes('~', last_token.end - first_token.start);
399 try stream.write("\n");
392 try stream.writeByte('\n');
400393}
401394
402395export fn stage2_DepTokenizer_init(input: [*]const u8, len: usize) stage2_DepTokenizer {
std/zig/parser_test.zig+9
......@@ -8,6 +8,15 @@ test "zig fmt: change use to usingnamespace" {
88 );
99}
1010
11test "zig fmt: whitespace fixes" {
12 try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}",
13 \\test "" {
14 \\ const hi = x;
15 \\}
16 \\
17 );
18}
19
1120test "zig fmt: while else err prong with no block" {
1221 try testCanonical(
1322 \\test "" {
std/zig/tokenizer.zig+1-4
......@@ -301,10 +301,7 @@ pub const Tokenizer = struct {
301301 const c = self.buffer[self.index];
302302 switch (state) {
303303 State.Start => switch (c) {
304 ' ' => {
305 result.start = self.index + 1;
306 },
307 '\n' => {
304 ' ', '\n', '\t', '\r' => {
308305 result.start = self.index + 1;
309306 },
310307 'c' => {