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

parser: unexpected token goto #240

Closed
kkharji opened this issue Aug 15, 2021 · 12 comments
Closed

parser: unexpected token goto #240

kkharji opened this issue Aug 15, 2021 · 12 comments

Comments

@kkharji
Copy link

kkharji commented Aug 15, 2021

Hello @JohnnyMorganz

I was trying to format the following file :

https://github.com/pwntester/octo.nvim/blob/master/lua/octo/model/octo-buffer.lua

but got the following message

Could not format file lua/octo/model/octo-buffer.lua: 
error parsing: error occurred while creating ast: 
unexpected token `goto`. (starting from line 171, character 9 and ending on line 171, character 13)

Additionally, when I commented that line I got similar error related to ::continue::

more info pwntester/octo.nvim#193

@JohnnyMorganz
Copy link
Owner

Hey @tami5

It looks like you have some Lua5.2+ code. How did you install stylua?
If you installed it through cargo, make sure you include --features lua52:

cargo install stylua --features lua52

If you installed through GitHub releases or if this is from the GitHub action, then there may be something else wrong here

@kkharji
Copy link
Author

kkharji commented Aug 16, 2021

Hey @tami5

It looks like you have some Lua5.2+ code. How did you install stylua?
If you installed it through cargo, make sure you include --features lua52:

cargo install stylua --features lua52

If you installed through GitHub releases or if this is from the GitHub action, then there may be something else wrong here

🤨 I don't think neovim is running on lua52, luajit is which as far as I know it's basically lua51. Maybe support this syntax is supported in luajit 🤔. I'm not sure.

@clason
Copy link

clason commented Aug 16, 2021

Yes, LuaJIT includes some extensions from Lua 5.2, and in particular goto and ::labels::; see https://luajit.org/extensions.html.

@kkharji
Copy link
Author

kkharji commented Aug 16, 2021

Thanks @clason, It would be cool to have a stylua version for luajit.

@JohnnyMorganz
Copy link
Owner

The LuaJIT extensions should be covered in Lua 5.2 mode (mainly the goto and label syntax, which is the same in both).

The only difference is when using goto as an identifier - if LuaJIT is built without the -DLUAJIT_ENABLE_LUA52COMPAT flag this becomes an issue (as shown in #229) https://luajit.org/extensions.html

In the case you showed though, this isn't an issue. Building with the Lua52 flag will work for your usecase

@pwntester
Copy link

Thanks @JohnnyMorganz! Can I configure https://github.com/JohnnyMorganz/stylua-action to use the lua52 flag?

@JohnnyMorganz
Copy link
Owner

Thanks @JohnnyMorganz! Can I configure https://github.com/JohnnyMorganz/stylua-action to use the lua52 flag?

It currently has all flags enabled (which hasn't proved a major issue thus far). Running it as-is should work

@pwntester
Copy link

pwntester commented Aug 18, 2021

Going a little bit off-issue (maybe), do you have any idea what can cause this error then?

@JohnnyMorganz
Copy link
Owner

Going a little bit off-issue (maybe), do you have any idea what can cause this error then?

Hm, thats a strange one. Let me take a look further

@JohnnyMorganz
Copy link
Owner

JohnnyMorganz commented Aug 19, 2021

Going a little bit off-issue (maybe), do you have any idea what can cause this error then?

Ah, I see the issue. In your lint.yml workflow file, you have this: https://github.com/pwntester/octo.nvim/blob/722b6b5985ad52a02017e861a469fa9018dc2a24/.github/workflows/lint.yml#L14

          args:  stylua --color always --check lua/

What this is essentially running is stylua stylua --color always --check lua/, so you are passing stylua again as an argument - it is trying to format all the files in a "stylua" directory, which doesn't exist!
It should be:

          args:  --color always --check lua/

Maybe the error message could be slightly easier to understand

(Sorry for the delay, got distracted!)

@pwntester
Copy link

🤦🏼 Thanks a lot, that fixed it!

@kkharji
Copy link
Author

kkharji commented Aug 19, 2021

😆 that was my bad, thanks @JohnnyMorganz . I guess this is no longer an issue

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

No branches or pull requests

4 participants