luals / luaparser Goto Github PK
View Code? Open in Web Editor NEWCustomized Lua parser for [lua-language-server](https://github.com/sumneko/lua-language-server).
License: MIT License
Customized Lua parser for [lua-language-server](https://github.com/sumneko/lua-language-server).
License: MIT License
我在本地跑main.lua
,打断点发现好像生产的ast中不会生成doc相关的内容,我也看到了您把test 'LuaDoc'
给注释掉了,这个parser目前不支持doc吗?
我想要看下doc是怎样被放在变量里的,怎么才能正确解析doc呢?
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.
这是非常罕见的场景, 并且建议避免编写这种代码.
local env = _ENV
_ENV, a = {}, 1
env.print(env.a, a) -- 1 nil
使用parser.compile
函数解析得到的state.ast.locals
会多出错误的局部变量_ENV
和a
.
整个多重赋值语句都会识别成local
变量定义, 不管是a, a.x, a[1]
形式, 生成的ast.type
字段都会被错误的标识成'local'
.
同时也会导致vscode插件错误提示.
用lua5.3进行编译会出现这个错误
error loading module 'lpeglabel' from file 'E:\025_Lua\LuaParser/bin/lpeglabel.dll':
请问有办法解决吗?
例如以下情况:
我看相应compile代码中,编译getname的结点时,是直接去最近的block中的locals
中寻找符号,因此只能拿到定义local的时候的信息,如果中间有setlocal
等动作,那么不能拿到真正的对象信息
比如这个地方有一个赋值语句id2 = id1
那么实际上id2
的对象信息应该绑定到id1
上,但是这个动作没有放在locals
表里,因此当编译local name = id2
这句话时,寻找id2
的过程中错过了id2 = id1
这一动作,导致name
被绑定到local id2 = 2
,这个地方是不是有改进的余地?
我觉得locals
里面是不是不应该放一个语法结构的结点,而是应该放变量代表的结点,这样的话,当变量的value变了,其他引用这个结点的对象也可以跟着变。
或者在guide.getLocal
的时候,不仅仅寻找locals
里的东西,还要寻找其他语句中的setlocal
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 ?
Hi, 我看Readme中, 提到了 Support dirty script
不知道什么意思? 还请赐教.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.