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

Syntax error though code is valid #127

Open
dimozaprianov opened this issue Jan 6, 2023 · 2 comments
Open

Syntax error though code is valid #127

dimozaprianov opened this issue Jan 6, 2023 · 2 comments

Comments

@dimozaprianov
Copy link

Currently the parser throws syntax error here, although it is perfectly valid lua code. When removing the newlines the parser behaves as expected.

    const ast = luaparse.parse(`
    l.v(function(v) 
    end) 
    {
    } 
    (
    )`
    )
@berbun
Copy link

berbun commented Mar 4, 2023

I performed a test, the parser is correct and you are wrong, it is very much invalid Lua code, tested with LuaJIT:

luajit: test.lua:5: ambiguous syntax (function call x new statement) near '('

When removing the newlines the parser behaves as expected.

Because, that would be syntactically valid Lua code then.

Conclusion
The following is invalid Lua code:

print()
{
}
(
)

due to newlines; that's just how Lua works, luaparser works correctly in this case by throwing the same syntax error.
The following is syntactically correct Lua code and luaparser does parse it as expected:

print(){}()

@Vurv78
Copy link

Vurv78 commented Apr 13, 2023

Not sure what luajit you're testing. Both work fine for me on luajit 2.1.0-beta3. This code is valid. And so the issue is valid.

Seems to also work on Lua 5.3.2, 5.3.4, 5.3.5, and Lua 5.4.3 tested here.

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

3 participants