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

Cannot process goto in v0.14.0 #505

Closed
jsumners opened this issue Jul 22, 2022 · 3 comments
Closed

Cannot process goto in v0.14.0 #505

jsumners opened this issue Jul 22, 2022 · 3 comments

Comments

@jsumners
Copy link

Given the following Lua:

local function foo(tbl)
  for k, _ in pairs(tbl) do
    if k == 'foo' then
      goto continue
    end
    print('proceeding with iteration')
  end

  ::continue::
  print('continue reached')
end

foo({ bar = 'bar', baz = 'baz', foo = 'foo', foobar = 'foobar' })

stylua@0.13.1 will correctly process the code:

❯ stylua --check .
Diff in ./foo.lua:
1   1    | local function foo(tbl)
2        |-  for k, _ in pairs(tbl) do
3        |-    if k == 'foo' then
4        |-      goto continue
5        |-    end
6        |-    print('proceeding with iteration')
7        |-  end
    2    |+	for k, _ in pairs(tbl) do
    3    |+		if k == "foo" then
    4    |+			goto continue
    5    |+		end
    6    |+		print("proceeding with iteration")
    7    |+	end
8   8    |
9        |-  ::continue::
10       |-  print('continue reached')
    9    |+	::continue::
    10   |+	print("continue reached")
11  11   | end
12  12   |
13       |-foo({ bar = 'bar', baz = 'baz', foo = 'foo', foobar = 'foobar' })
14       |-
    13   |+foo({ bar = "bar", baz = "baz", foo = "foo", foobar = "foobar" })

/tmp/22
❯ stylua --version
stylua 0.13.1

But stylua@0.14.0 complains about the goto statement:

❯ docker run --rm -v "$(pwd)":/src:ro -w /src --entrypoint /usr/local/bin/stylua luajit --check .
error: could not format file ./foo.lua: error parsing: error occurred while creating ast: unexpected token `goto`. (starting from line 4, character 7 and ending on line 4, character 11)
additional information: expected 'end'

/tmp/22 took 2s
❯ docker run --rm -v "$(pwd)":/src:ro -w /src --entrypoint /usr/local/bin/stylua luajit --version
stylua 0.14.0
@jsumners jsumners changed the title Cannot process goto in v14.0 Cannot process goto in v0.14.0 Jul 22, 2022
@jsumners
Copy link
Author

It seems the issue is resolved by #407 (comment)

I don't know much of anything about the Lua community, but according to http://www.lua.org/versions.html Lua 5.2 was released in 2011 and received its last update in 2015. I would think that makes it a candidate to be the baseline syntax for stylua.

@JohnnyMorganz
Copy link
Owner

By default we still have 5.1 as baseline as it still seems to be widely used, and everything builds on top of that.

I want to make the experience nicer for using different syntax though, as mentioned in those issues. Parser selection is currently at compile time but we want to move it to runtime. (There is also another issue in the GitHub releases where we merge all the parsers together for user simplicity, but that has issues)

@jsumners
Copy link
Author

I suppose I'll close this.

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

2 participants