Code Monkey home page Code Monkey logo

luaparser's People

Contributors

sumneko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

luaparser's Issues

LuaDoc测试跑不过;生成的ast中不包含doc信息

我在本地跑main.lua,打断点发现好像生产的ast中不会生成doc相关的内容,我也看到了您把test 'LuaDoc'给注释掉了,这个parser目前不支持doc吗?
我想要看下doc是怎样被放在变量里的,怎么才能正确解析doc呢?

Investigate if saving closures to local variables provides performance benefits

Repeatedly creating a function closure in functions that are called often may lead to decreased performance. I have an example here.

 while true do
      local name
      try(function () -- This function is constantly being recreated
          local returnName = parseName('doc.return.name', typeUnit)
                          or parseDots('doc.return.name', typeUnit)
          if not returnName then
              return false
          end
          if checkToken('symbol', ':', 1) then
              nextToken()
              name = returnName
              return true
          end
          if returnName[1] == '...' then
              name = returnName
              return false
          end
          return false
      end)
      local rtn = parseType(typeUnit)
      if not rtn then
          break
      end
      rtn.name = name
      if checkToken('symbol', '?', 1) then
          nextToken()
          rtn.optional = true
      end
      typeUnit.returns[#typeUnit.returns+1] = rtn
      if checkToken('symbol', ',', 1) then
          nextToken()
      else
          break
      end
  end

Instead I propose the following:

local checkFunc = function()
  --function body here
end
while true do
  local name
  try(checkFunc())
  -- the rest of the loop here
end

The same approach can be applied to some other places with functions that constantly create new anonymous functions. These functions can be saved to a variable to avoid the VM from constantly creating (and compiling) new functions.

Are there some scripts to test the performance of changes to the parser? Of course, some kind of benchmarks before and after the changes should be used to see if my proposal improves performance.

BUG: 当_ENV作为多重赋值的第一个变量时, 后续变量会错误的识别成局部变量.

这是非常罕见的场景, 并且建议避免编写这种代码.

local env = _ENV
_ENV, a = {}, 1
env.print(env.a, a) -- 1 nil

使用parser.compile函数解析得到的state.ast.locals会多出错误的局部变量_ENVa.
整个多重赋值语句都会识别成local变量定义, 不管是a, a.x, a[1]形式, 生成的ast.type字段都会被错误的标识成'local'.

同时也会导致vscode插件错误提示.
image

error loading module 'lpeglabel'

用lua5.3进行编译会出现这个错误
error loading module 'lpeglabel' from file 'E:\025_Lua\LuaParser/bin/lpeglabel.dll':
请问有办法解决吗?

compile:getname时,只能获取到定义时的信息,而不能获取到赋值改变时的信息

例如以下情况:
image
我看相应compile代码中,编译getname的结点时,是直接去最近的block中的locals中寻找符号,因此只能拿到定义local的时候的信息,如果中间有setlocal等动作,那么不能拿到真正的对象信息
image
比如这个地方有一个赋值语句id2 = id1那么实际上id2的对象信息应该绑定到id1上,但是这个动作没有放在locals表里,因此当编译local name = id2这句话时,寻找id2的过程中错过了id2 = id1这一动作,导致name被绑定到local id2 = 2,这个地方是不是有改进的余地?
我觉得locals里面是不是不应该放一个语法结构的结点,而是应该放变量代表的结点,这样的话,当变量的value变了,其他引用这个结点的对象也可以跟着变。
或者在guide.getLocal的时候,不仅仅寻找locals里的东西,还要寻找其他语句中的setlocal

执行main.lua报错 src\parser\guide.lua:1809: unexpected symbol near '<'

G:\Lua\lua-5.3.6\build\lua.exe: error loading module 'parser.guide' from file 'g:/Lua/LuaParser/test/main.lua\..\..\src\parser\guide.lua':
        g:/Lua/LuaParser/test/main.lua\..\..\src\parser\guide.lua:1809: unexpected symbol near '<'
stack traceback:
        [C]: in ?
        [C]: in function 'require'
        g:/Lua/LuaParser/test/main.lua\..\..\src\parser\compile.lua:1: in main chunk
        [C]: in function 'require'
        g:/Lua/LuaParser/test/main.lua\..\..\src\parser\init.lua:4: in main chunk
        [C]: in function 'require'
        g:/Lua/LuaParser/test/main.lua:7: in main chunk
        [C]: in ?

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.