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

"attempt to get length of a number value (local 'sfail')" when parsing wrong syntax #15

Closed
PhilipRoman opened this issue Aug 31, 2019 · 2 comments
Labels

Comments

@PhilipRoman
Copy link

PhilipRoman commented Aug 31, 2019

Error

lua5.3: /usr/local/share/lua/5.3/lua-parser/parser.lua:478: attempt to get length of a number value (local 'sfail')
stack traceback:
    /usr/local/share/lua/5.3/lua-parser/parser.lua:478: in function 'lua-parser.parser.parse'
    <my code>
    [C]: in ?

Steps to reproduce

require 'luarocks.loader'
local parser = require 'lua-parser.parser'

local source = "while true do"
local ast, err = parser.parse(source, "sourcefile.lua")

Seems like this happens with any invalid syntax.

Versions

luarocks 3.0.4
lua-parser 1.0.0-1
LPegLabel 1.5.0-1
Lua 5.3.3

Additional info

This issue does not occur with lua-parser 0.1.1-1. The parse function returns normally and error message is sourcefile.lua:1:13: syntax error, unexpected 'EOF', expecting 'end', 'return', '(', 'Name', 'goto', 'break', '::', 'local', 'function', 'repeat', 'for', 'do', 'while', 'if', ';'

@andremm
Copy link
Owner

andremm commented Oct 26, 2019

Thanks for the report @PhilipRoman! This issue was introduced by LPegLabel 1.5.0 and it indeed will happen to any invalid syntax, because now LPegLabel is returning the subject position (number) related to the error instead of the subject itself (string) where the failure occurred. I still have to see how to fix this because this change is breaking several tests due to different error positions being reported by LPegLabel. For now, I recommend using either lua-parser 1.0.0 with LPegLab 1.4.0 or lua-parser 0.1.1, which is basically the same parser, but using LPeg instead of LpegLabel.

@andremm
Copy link
Owner

andremm commented Oct 26, 2019

The solution was really simple. I just needed to use the error position being returned, as it wasn't necessary to calculate it anymore. I generated a new version to make sure the right LPegLabel version is used with the fix, that is, from now on lua-parser 1.0.1 requires at least LPegLabel 1.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants