Giter Site home page Giter Site logo

Problem in pp.dump about lua-parser HOT 7 CLOSED

andremm avatar andremm commented on June 27, 2024
Problem in pp.dump

from lua-parser.

Comments (7)

andremm avatar andremm commented on June 27, 2024 1

The command line below will simply throw an error if without this commit .

What error?
Do you mean the error is printing nil on the screen?

Thanks a lot and all best to you. lua-parser is a pretty cool project πŸ‘

Thank you for using lua-parser! :)

from lua-parser.

hnes avatar hnes commented on June 27, 2024

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
      }
    }

from lua-parser.

hnes avatar hnes commented on June 27, 2024

The error is that when string.format find the '%s' in its 1st arg refers a nil value, it will simply throw an error.

> 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]: ?
>

from lua-parser.

hnes avatar hnes commented on June 27, 2024

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]: ?

from lua-parser.

andremm avatar andremm commented on June 27, 2024
$ 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?

from lua-parser.

hnes avatar hnes commented on June 27, 2024

No problem anymore. Thanks a lot :D πŸ‘

from lua-parser.

andremm avatar andremm commented on June 27, 2024

No problem anymore. Thanks a lot :D πŸ‘

Thanks for the report!

from lua-parser.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.