ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.06k stars 2.56k forks source link

Allow tab whitespace character to be placed inside of string and command #22030

Open rxvoid opened 2 days ago

rxvoid commented 2 days ago

Description

Currently, the 'dev' (or maybe even the previous) version of Zig doesn't allow tab whitespace character (not tab escape sequence) to be placed inside of a string and a command. That would make programming in Zig a little bit harder, as Zig allow tabs to be used as indentation but doesn't allow it to be placed inside of a command, because I (and I believe many other devs) use command as a way to temporary mark some piece of code as unused and so I can change it later or maybe just for debugging purpose without ever deleting it. Zig also doesn't allow tabs inside of a string, that would also make indentation for terminal output or any other work that needs string indentation a little bit harder as we need to use '\t' escape sequence or even worse we have to manually use spaces so we can see the final string in our code editor when we code it.

Zig Version

0.14.0-dev.2245+4fc295dc0

Steps to Reproduce and Observed Output

Consider the following code:

const std = @import("std");

pub fn main() void {
    const price = 80;
    std.debug.print("Price:     ${}", .{ price }) catch {};
    // switch (comptime @import("builtin").cpu.arch.endian()) {
    //  .big    => std.debug.print("BIG."),
    //  .little => std.debug.print("little.")
    // }
}

When we compile it, the compiler will produce the following error message:

test.zig:5:18: error: expected expression, found 'invalid token'
 std.debug.print("Price:  ${}", .{ price }) catch {};
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When we change the string indentation to either '\t' or spaces, we'll get the following error:

test.zig:7:2: error: expected statement, found 'invalid token'
 //  .big    => std.debug.print("BIG."),
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Output

Zig should allow tabs inside of string and command, and the code above should work and compile fine without any compilation error.