summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-14 20:00:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-14 20:00:11 +0800
commit5306630e69f2129fbf7ced43f63ff041f3a513a3 (patch)
treee2108aa8a36c4cbf93aeca9602f1e8db337f2047 /server-beta/src
parent577a4d73c83b138097a7e95c78e7c9336e579803 (diff)
downloadlua-language-server-5306630e69f2129fbf7ced43f63ff041f3a513a3.zip
更新 parser
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/parser/compile.lua71
-rw-r--r--server-beta/src/parser/guide.lua2
-rw-r--r--server-beta/src/parser/parse.lua1
3 files changed, 51 insertions, 23 deletions
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index bf60e7ba..2fdab43d 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -1,10 +1,20 @@
local guide = require 'parser.guide'
local type = type
+local specials = {
+ ['_G'] = true,
+ ['rawset'] = true,
+ ['rawget'] = true,
+ ['setmetatable'] = true,
+ ['require'] = true,
+ ['dofile'] = true,
+ ['loadfile'] = true,
+}
+
_ENV = nil
local LocalLimit = 200
-local pushError, Compile, CompileBlock, Block, GoToTag, ENVMode, Compiled, LocalCount
+local pushError, Compile, CompileBlock, Block, GoToTag, ENVMode, Compiled, LocalCount, Version, Special
local function addRef(node, obj)
if not node.ref then
@@ -14,6 +24,14 @@ local function addRef(node, obj)
obj.node = node
end
+local function addSpecial(name, obj)
+ if not Special[name] then
+ Special[name] = {}
+ end
+ Special[name][#Special[name]+1] = obj
+ obj.special = name
+end
+
local vmMap = {
['getname'] = function (obj)
local loc = guide.getLocal(obj, obj[1], obj.start)
@@ -21,6 +39,9 @@ local vmMap = {
obj.type = 'getlocal'
obj.loc = loc
addRef(loc, obj)
+ if loc.special then
+ addSpecial(loc.special, obj)
+ end
else
obj.type = 'getglobal'
if ENVMode == '_ENV' then
@@ -29,6 +50,10 @@ local vmMap = {
addRef(node, obj)
end
end
+ local name = obj[1]
+ if specials[name] then
+ addSpecial(name, obj)
+ end
end
return obj
end,
@@ -208,6 +233,9 @@ local vmMap = {
obj.localfunction = nil
end
Compile(obj.value, obj)
+ if obj.value and obj.value.special then
+ addSpecial(obj.value.special, obj)
+ end
end,
['setfield'] = function (obj)
Compile(obj.node, obj)
@@ -250,18 +278,20 @@ local vmMap = {
local name = obj[1]
local label = guide.getLabel(block, name)
if label then
- pushError {
- type = 'REDEFINED_LABEL',
- start = obj.start,
- finish = obj.finish,
- related = {
- {
- message = 'REDEFINED_LABEL',
- start = label.start,
- finish = label.finish,
+ if Version == 'Lua 5.4'
+ or block == guide.getBlock(label) then
+ pushError {
+ type = 'REDEFINED_LABEL',
+ start = obj.start,
+ finish = obj.finish,
+ relative = {
+ {
+ label.start,
+ label.finish,
+ }
}
}
- }
+ end
end
block.labels[name] = obj
end
@@ -423,10 +453,7 @@ local function compileGoTo(obj)
}
return
end
- if not label.ref then
- label.ref = {}
- end
- label.ref[#label.ref+1] = obj
+ label.ref = obj
-- 如果有局部变量在 goto 与 label 之间声明,
-- 并在 label 之后使用,则算作语法错误
@@ -463,16 +490,14 @@ local function compileGoTo(obj)
info = {
loc = loc[1],
},
- related = {
+ relative = {
{
- message = 'JUMPED_LABEL',
- start = label.start,
- finish = label.finish,
+ start = label.start,
+ finish = label.finish,
},
{
- message = 'JUMPED_LOCAL',
- start = loc.start,
- finish = loc.finish,
+ start = loc.start,
+ finish = loc.finish,
}
},
}
@@ -503,6 +528,8 @@ return function (self, lua, mode, version)
Compiled = {}
GoToTag = {}
LocalCount = 0
+ Version = version
+ Special = state.special
if type(state.ast) == 'table' then
Compile(state.ast)
end
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index 9c0a6794..bc19c816 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -378,7 +378,7 @@ function m.positionOf(lines, offset)
local line = lines[row]
if offset < line.start then
max = row - 1
- elseif offset >= line.finish then
+ elseif offset > line.finish then
min = row + 1
else
return row, offset - line.start + 1
diff --git a/server-beta/src/parser/parse.lua b/server-beta/src/parser/parse.lua
index bbc01b10..ce6e74c1 100644
--- a/server-beta/src/parser/parse.lua
+++ b/server-beta/src/parser/parse.lua
@@ -8,6 +8,7 @@ return function (self, lua, mode, version)
lua = lua,
emmy = {},
root = {},
+ special = {},
errs = errs,
diags = diags,
pushError = function (err)