-
Notifications
You must be signed in to change notification settings - Fork 27
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
Problem in pp.dump #9
Comments
Detail: [tag] = Localrec
[pos] = 11
[1] = {
[1] = {
[tag] = Id
[pos] = 20
[1] = x
}
} [tag] = Localrec
[pos] = 11
[1] = {
[tag] = nil -- <<---
[pos] = nil -- <<---
[1] = {
[tag] = Id
[pos] = 20
[1] = x
}
} |
What error?
Thank you for using lua-parser! :) |
The error is that when > return string.format("%s[tag] = %s\n", string.rep(" ", 2), nil)
stdin:1: bad argument #3 to 'format' (string expected, got nil)
stack traceback:
[C]: in function 'format'
stdin:1: in main chunk
[C]: ?
> |
pp.lua:line:314: function pp.dump (t, i)
if i == nil then i = 0 end
io.write(string.format("{\n"))
io.write(string.format("%s[tag] = %s\n", string.rep(" ", i+2), t.tag))
io.write(string.format("%s[pos] = %s\n", string.rep(" ", i+2), t.pos))
for k,v in ipairs(t) do
io.write(string.format("%s[%s] = ", string.rep(" ", i+2), tostring(k)))
if type(v) == "table" then
pp.dump(v,i+2)
else
io.write(string.format("%s\n", tostring(v)))
end
end
io.write(string.format("%s}\n", string.rep(" ", i)))
end And the error below would occur sometimes as the member "tag" and "pos" is not always present in a table which is in the AST ( Sorry for that I did not explain it clearly before). $ lua parse.lua "x=2;local function x() end"
lua: /usr/share/lua/5.1/lua-parser/pp.lua:314: bad argument #3 to 'format' (string expected, got nil)
stack traceback:
[C]: in function 'format'
/usr/share/lua/5.1/lua-parser/pp.lua:314: in function 'dump'
/usr/share/lua/5.1/lua-parser/pp.lua:319: in function 'dump'
/usr/share/lua/5.1/lua-parser/pp.lua:319: in function 'dump'
parse_str.lua:54: in main chunk
[C]: ? |
Thanks! It looks like this is an error specific to Lua version 5.1. I just pushed a commit that should solve this problem. Can you please check whether it works? |
No problem anymore. Thanks a lot :D 👍 |
Thanks for the report! |
The command line below will simply throw an error if without this commit .
Expected output after this commit:
I don't know whether this is just a little implementation problem within pp.dump or actually due to the inconsistence of the AST which generated by the parser.
Thanks a lot and all best to you. lua-parser is a pretty cool project 👍
The text was updated successfully, but these errors were encountered: