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

Parsing comments before module headers #1135

Open
rtfeldman opened this issue Mar 31, 2021 · 3 comments
Open

Parsing comments before module headers #1135

rtfeldman opened this issue Mar 31, 2021 · 3 comments
Labels
bug Something isn't working parsing

Comments

@rtfeldman
Copy link
Contributor

rtfeldman commented Mar 31, 2021

Currently, the parser fails when trying to parse a module that has a comment before its module header.

This is unfortunate because if it worked, we could have "roc scripts" on UNIX systems as easily as making this the first line in the module:

#!/usr/bin/env roc run

...and then marking Example.roc executable. I verified that this technique works, except that whenever you execute Example.roc, it immediately crashes with a parse error. 😄

@rtfeldman rtfeldman added bug Something isn't working parsing labels Mar 31, 2021
@Ivo-Balbaert
Copy link
Contributor

Ivo-Balbaert commented Aug 2, 2023

For this Example.roc program:

#!/usr/bin/env roc
# comment abc
# comment cde
app "helloWorld"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.4.0/DI4lqn7LIZs8ZrCDUgLK-tHHpQmxGF1ZrlevRKq5LXk.tar.br" }
    imports [pf.Stdout]
    provides [main] to pf

main =
    Stdout.line "Hello, World!"

making it executable and running with ./Example.roc works (Ubuntu 22).

(However roc run doesn't work:
/usr/bin/env: ‘roc run’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines)

Perhaps this bug can be declared as solved and the issue closed? @Anton-4 ?

@lukewilliamboswell
Copy link
Collaborator

No longer reproducible.

Tested using

#!/usr/bin/env roc
# Some comment
app ""
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
    }
    imports [pf.Stdout]
    provides [main] to pf

main = Stdout.line "Hi"
13:37:26 ~/Documents/GitHub/roc main $ chmod +x test.roc           
15:13:47 ~/Documents/GitHub/roc main $ ./test.roc
Hi

@evanrelf
Copy link
Contributor

evanrelf commented May 10, 2024

I think the compiler has regressed on this. I'm using Roc built with Nix from b8d9367.

Taking Luke's example above verbatim:

#!/usr/bin/env roc
# Some comment
app ""
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
    }
    imports [pf.Stdout]
    provides [main] to pf

main = Stdout.line "Hi"

Things work fine:

$ ./test.roc
Hi

But formatting the file changes it to a new syntax:

# !/usr/bin/env roc
# Some comment
app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
}

import pf.Stdout

main = Stdout.line "Hi"

And running that doesn't work:

$ ./test.roc
./test.roc: line 3: app: command not found
./test.roc: line 4: pf:: command not found
./test.roc: line 5: syntax error near unexpected token `}'
./test.roc: line 5: `}'

It seems the reason is because the formatter adds a space after the first # in the shebang, and roc isn't expecting that, so it stops treating it like a script. Removing that space fixes things.

@Anton-4 Anton-4 reopened this May 10, 2024
evanrelf added a commit to evanrelf/roc that referenced this issue Jun 19, 2024
Fixes the regression I described in [roc-lang#1135].

[roc-lang#1135]: roc-lang#1135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parsing
Projects
None yet
Development

No branches or pull requests

5 participants