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

Add support for Unix shebangs #2175

Merged
merged 1 commit into from
May 2, 2021
Merged

Add support for Unix shebangs #2175

merged 1 commit into from
May 2, 2021

Conversation

Gabriella439
Copy link
Collaborator

… as standardized in dhall-lang/dhall-lang#1158

@@ -757,7 +766,7 @@ parsers embedded = Parsers {..}
where
predicate c = c == '$' || c == '\''

endOfLine = do
endOfLine_ = do
a <- "\n" <|> "\r\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this be replaced by a <- endOfLine ?

@basile-henry
Copy link
Collaborator

It would be nice to support multiple lines of shebang so that we could use the nix-shell shebangs.

I have just tested this branch with the following (from the root of the dhall-haskell repo):

#! /usr/bin/env nix-shell
#! nix-shell -i "dhall --file" -p "(import ./.).dhall"

42

Which currently gives me:

➜ ./test.dhall
dhall:
Error: Invalid input

./test.dhall:2:1:
  |
2 | #! nix-shell -i "dhall --file" -p "(import ./.).dhall"
  | ^^^^^^^^
unexpected "#! nix-s"
expecting expression or whitespace

I saw the dhall-lang PR for this, but didn't think about mentioning the nix-shell shebang use case at the time 😅

@Gabriella439
Copy link
Collaborator Author

@basile-henry: Yeah, that would first require an upstream change to the standard, which we can still do afterwards

@TristanCacqueray
Copy link
Collaborator

It seems like nix-shell shebang is relying on the fact that # is a comment in the target language, but that does not always work. Though that seems like a good thing to support.

Alternatively, perhaps nix-shell could be modified to also consider --! nix-shell -i "dhall --file" -p dhall as a valid extra shebang line, but that would not look good.

@TristanCacqueray
Copy link
Collaborator

Also it is unfortunate that #!/usr/bin/env -S nix-shell -p dhall -i "dhall --file" does not work.

@basile-henry
Copy link
Collaborator

nix-shell shebang is relying on the fact that # is a comment in the target language

That's probably true for bash and python. However I have seen multi-line shebangs with nix-shell for Haskell too, usually with GHC's runhaskell. That probably means that GHC takes this edge case specifically into account?

@TristanCacqueray
Copy link
Collaborator

runhaskell does something special where it ignores any lines starting with '#!', not just the first ones, according to: https://gitlab.haskell.org/ghc/ghc/-/blob/e61d2d47c4942c829ec98016be5aa5ae36982524/compiler/GHC/Parser/Lexer.x#L279

@Gabriella439 Gabriella439 merged commit e2f4232 into master May 2, 2021
@Gabriella439 Gabriella439 deleted the gabriel/shebangs branch May 2, 2021 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants