In the following code, a TAB char is in s
. The code doesn’t compile now:
pub fn main() !void {
// const s = " "
}
zig version: 0.14.0-dev.1951+857383689
In the following code, a TAB char is in s
. The code doesn’t compile now:
pub fn main() !void {
// const s = " "
}
zig version: 0.14.0-dev.1951+857383689
I think this was not done on purpose.
Sadly, it was done on purpose. In the specs it says that tabs inside of comments and multi-line string literals are illegal: grammar clarifications regarding tabs and carriage returns · Issue #38 · ziglang/zig-spec · GitHub
And this has been implemented recently in std.zig.tokenizer: simplification and spec conformance by andrewrk · Pull Request #20885 · ziglang/zig · GitHub
It’s kind of annoying in my opinion and I hope they revert it.
But I guess in your case you can fix it by using \t
instead of putting the tab directly into the string literal (and to be honest tabs in string literals are kind of ugly anyways).
I just installed v0.14.0 and noticed the ban on tab chars in comments. The purported justification is that “it is ambiguous how [TAB] should be rendered”. But when are comments ever “rendered” by the compiler? What does that even mean?
It said whenever rendered: not rendered by the compiler.
So…
I see the point about doc comments, but for ordinary //single-line comments what is the grammatical interest in controlling how they are displayed? From the perspective of the lowly, individual, non-corporate, hobbyist programmer like myself, it’s a pain that I can no longer simply “comment out” lines of code that start with tabs. Not that I want to be a tail wagging the dog… And, off-topic but tangentially related, why are multi-line comments not supported? Seems to me coders need a convenient way to disable blocks of code during development.
I don’t mean to rant. I love coding in Zig, and appreciate the added challenge of learning a language that is under active development and therefore constantly changing. Just adding my //two cents.
many editors have the feature of replacing tabs with spaces, zig fmt
also does this.
most editors have a feature to comment selected code with a key bind
Because zig uses a no-context parser. It is possible to parse a line of zig code without seeing any other lines, which helps with parallelization. Having mutli-line comments breaks this property.