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(...@@ -375,28 +375,21 @@ fn printErrMsgToFile(
375 const text = text_buf.toOwnedSlice();375 const text = text_buf.toOwnedSlice();
376376
377 const stream = &file.outStream().stream;377 const stream = &file.outStream().stream;
378 if (!color_on) {378 try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
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 }
388379
389 try stream.print(380 if (!color_on) return;
390 "{}:{}:{}: error: {}\n{}\n",381
391 path,382 // Print \r and \t as one space each so that column counts line up
392 start_loc.line + 1,383 for (tree.source[start_loc.line_start..start_loc.line_end]) |byte| {
393 start_loc.column + 1,384 try stream.writeByte(switch (byte) {
394 text,385 '\r', '\t' => ' ',
395 tree.source[start_loc.line_start..start_loc.line_end],386 else => byte,
396 );387 });
388 }
389 try stream.writeByte('\n');
397 try stream.writeByteNTimes(' ', start_loc.column);390 try stream.writeByteNTimes(' ', start_loc.column);
398 try stream.writeByteNTimes('~', last_token.end - first_token.start);391 try stream.writeByteNTimes('~', last_token.end - first_token.start);
399 try stream.write("\n");392 try stream.writeByte('\n');
400}393}
401394
402export fn stage2_DepTokenizer_init(input: [*]const u8, len: usize) stage2_DepTokenizer {395export 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" {...@@ -8,6 +8,15 @@ test "zig fmt: change use to usingnamespace" {
8 );8 );
9}9}
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
11test "zig fmt: while else err prong with no block" {20test "zig fmt: while else err prong with no block" {
12 try testCanonical(21 try testCanonical(
13 \\test "" {22 \\test "" {
std/zig/tokenizer.zig+1-4
...@@ -301,10 +301,7 @@ pub const Tokenizer = struct {...@@ -301,10 +301,7 @@ pub const Tokenizer = struct {
301 const c = self.buffer[self.index];301 const c = self.buffer[self.index];
302 switch (state) {302 switch (state) {
303 State.Start => switch (c) {303 State.Start => switch (c) {
304 ' ' => {304 ' ', '\n', '\t', '\r' => {
305 result.start = self.index + 1;
306 },
307 '\n' => {
308 result.start = self.index + 1;305 result.start = self.index + 1;
309 },306 },
310 'c' => {307 'c' => {