Skip to content

zig fmt does not handle shebang lines #1546

Closed

Description

@tiehuis

This should be handled at the parser level.

#!/bin/zig

pub fn main() void {
    const a = 5;
}
$ zig2 fmt t.zig 
t.zig:1:1: error: Expected variable declaration or function, found Invalid
#!/bin/zig
~

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    frontendTokenization, parsing, AstGen, Sema, and Liveness.
    on Sep 18, 2018
  2. added this to the 0.4.0 milestone on Sep 18, 2018
  3. andrewrk commented on Sep 18, 2018

    @andrewrk
    Member

    This should be handled at the parser level.

    I started looking at this, and it seemed easiest to create Token.ShebangLine. It would only show up if the first 2 bytes of the file were #!, and it could only be the first token, and would be guaranteed to only show up once total.

    The parser would look at the first token and skip it if it is a shebang line, otherwise put it back and continue.

    Do you think I shouldn't do it this way?

  4. andrewrk commented on Sep 18, 2018

    @andrewrk
    Member

    I went ahead and did it since this is better than status quo, but feel free to change the implementation if you have a better way.

  5. tiehuis commented on Sep 19, 2018

    @tiehuis
    MemberAuthor

    This solution is good. Easy for external users when using std/zig.

  6. modified the milestones: 0.4.0, 0.3.0 on Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions