Commit 4f43a4b30f
Changed files (3)
src-self-hosted
std
src-self-hosted/stage1.zig
@@ -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 {
std/zig/parser_test.zig
@@ -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 "" {
std/zig/tokenizer.zig
@@ -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' => {