Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment line error: expected type expression, found 'invalid token' #20937

Closed
chrboesch opened this issue Aug 4, 2024 · 9 comments
Closed

Comment line error: expected type expression, found 'invalid token' #20937

chrboesch opened this issue Aug 4, 2024 · 9 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@chrboesch
Copy link
Contributor

Zig Version

0.14.0-dev.839+a931bfada

Steps to Reproduce and Observed Behavior

In the ziglings exercises "103_tokenization.zig" the compiler throws an error from a comment line.

Here is an extract of the exercise to reproduce the error:

// 	My name is Ozymandias, King of Kings;
// 	Look on my Works, ye Mighty, and despair!
// 	 by Percy Bysshe Shelley
//
//
const std = @import("std");
const print = std.debug.print;

pub fn main() !void {

    // our input
    const poem =
        \\My name is Ozymandias, King of Kings;
        \\Look on my Works, ye Mighty, and despair!
    ;

    // now the tokenizer, but what do we need here?
    var it = std.mem.tokenizeAny(u8, poem, " ,;!\n");

    // print all words and count them
    var cnt: usize = 0;
    while (it.next()) |word| {
        cnt += 1;
        print("{s}\n", .{word});
    }

    // print the result
    print("This little poem has {d} words!\n", .{cnt});
}
‹test› » zig run 103_tokenization.zig 
103_tokenization.zig:1:1: error: expected type expression, found 'invalid token'
//  My name is Ozymandias, King of Kings;

Expected Behavior

No error.

@chrboesch chrboesch added the bug Observed behavior contradicts documented or intended behavior label Aug 4, 2024
@alexrp
Copy link
Member

alexrp commented Aug 4, 2024

#20928

@chrboesch
Copy link
Contributor Author

After I took a look in the binary version of the source code, I found the reason for this error. There is a TAB in the comment.

@chrboesch
Copy link
Contributor Author

@alexrp Thanks. Didn't find that issue because I searched for the error message.

@plaukiu
Copy link

plaukiu commented Aug 16, 2024

zig could at least say that it's a tab, not just 'invalid token'. quite unhelpful with such invisible characters.

@mpfaff
Copy link
Contributor

mpfaff commented Aug 23, 2024

After I took a look in the binary version of the source code, I found the reason for this error. There is a TAB in the comment.

Why is that a valid reason to error? Comments should have no restrictions on content.

@chrboesch
Copy link
Contributor Author

Yes and no. Comments can be used to automatically generate documentation. In this case, it's also content.

@vladimir-popov
Copy link

But for documentation zig has special syntax of comments. Why the regular comments should have any restrictions?

@relector-tuxnix
Copy link

This is not good design or considerate to the developer due to a white character being quite difficult to debug. Some additional context around the invalid "token" would be much better and likely save thousands of cumulative man hours of debugging and unraveling the mystery of Where's Wally.

@Vexu
Copy link
Member

Vexu commented Oct 15, 2024

This is a duplicate of #20900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

7 participants