summaryrefslogtreecommitdiff
path: root/server-beta/src/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-29 16:21:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-29 16:21:58 +0800
commit41b4fe57bf46f5e67a8f41bde4ded038955e178d (patch)
treeadb96c0c9243a009de73fc37c2baeb440949e6fe /server-beta/src/parser
parent32772cbf3b5fc4e01cc47b8339bdbdf19b743711 (diff)
downloadlua-language-server-41b4fe57bf46f5e67a8f41bde4ded038955e178d.zip
暂存
Diffstat (limited to 'server-beta/src/parser')
-rw-r--r--server-beta/src/parser/ast.lua17
-rw-r--r--server-beta/src/parser/compile.lua9
-rw-r--r--server-beta/src/parser/guide.lua27
3 files changed, 39 insertions, 14 deletions
diff --git a/server-beta/src/parser/ast.lua b/server-beta/src/parser/ast.lua
index cacb0e13..8094cc73 100644
--- a/server-beta/src/parser/ast.lua
+++ b/server-beta/src/parser/ast.lua
@@ -124,6 +124,9 @@ local function createLocal(key, effect, value, attrs)
key.effect = effect
key.value = value
key.attrs = attrs
+ if value then
+ key.range = value.finish
+ end
return key
end
@@ -179,7 +182,8 @@ local function packList(start, list, finish)
for i = count + 1, #list do
list[i] = nil
end
- list.start = start
+ list.type = 'list'
+ list.start = start
list.finish = finish - 1
return list
end
@@ -995,6 +999,9 @@ local Defs = {
key.type = 'setindex'
key.value = getValue(values, i)
end
+ if key.value then
+ key.range = key.value.finish
+ end
end
return tableUnpack(keys)
end,
@@ -1177,20 +1184,22 @@ local Defs = {
block.type = 'in'
block.start = start
block.finish = finish - 1
- block.keys = {}
+ block.keys = keys
local values
if func then
local call = createCall(exp, func.finish + 1, exp.finish)
call.node = func
+ call.start = func.start
values = { call }
+ keys.range = call.finish
end
for i = 1, #keys do
local loc = keys[i]
if values then
- block.keys[i] = createLocal(loc, blockStart, getValue(values, i))
+ createLocal(loc, blockStart, getValue(values, i))
else
- block.keys[i] = createLocal(loc, blockStart)
+ createLocal(loc, blockStart)
end
end
checkMissEnd(start)
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index 03632c03..90b3f269 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -3,7 +3,7 @@ local type = type
_ENV = nil
-local pushError, Compile, CompileBlock, Cache, Block, GoToTag, Version, ENVMode
+local pushError, Compile, CompileBlock, Cache, Block, GoToTag, Version, ENVMode, Compiled
--[[
-- value 类右字面量创建,在set get call中传递
@@ -416,6 +416,10 @@ function Compile(obj, parent)
if not obj then
return nil
end
+ if Compiled[obj] then
+ return
+ end
+ Compiled[obj] = true
local f = vmMap[obj.type]
if not f then
return
@@ -510,11 +514,14 @@ return function (self, lua, mode, version)
ENVMode = '_ENV'
end
Cache = {}
+ Compiled = {}
GoToTag = {}
if type(state.ast) == 'table' then
Compile(state.ast)
end
PostCompile()
Cache = nil
+ Compiled = nil
+ GoToTag = nil
return state
end
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index 095a975e..da851138 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -26,26 +26,35 @@ local breakBlockTypes = {
}
m.childMap = {
+ ['main'] = {'#'},
['repeat'] = {'#', 'filter'},
['while'] = {'filter', '#'},
['in'] = {'keys', '#'},
['loop'] = {'loc', 'max', 'step', '#'},
+ ['if'] = {'#'},
['ifblock'] = {'filter', '#'},
['elseifblock'] = {'filter', '#'},
+ ['elseblock'] = {'#'},
['setfield'] = {'node', 'value'},
['local'] = {'attrs', 'value'},
['setlocal'] = {'value'},
+ ['return'] = {'#'},
+ ['do'] = {'#'},
['index'] = {'index'},
+ ['table'] = {'#'},
['tableindex'] = {'index', 'value'},
['tablefield'] = {'value'},
['function'] = {'args'},
+ ['funcargs'] = {'#'},
['setmethod'] = {'node', 'method', 'value'},
['getmethod'] = {'node', 'method'},
['setindex'] = {'node', 'index', 'value'},
['getindex'] = {'node', 'index'},
['paren'] = {'exp'},
['call'] = {'node', 'args'},
+ ['callargs'] = {'#'},
['getfield'] = {'node'},
+ ['list'] = {'#'},
}
--- 寻找所在函数
@@ -196,12 +205,14 @@ end
--- 判断source是否包含offset
function m.isContain(source, offset)
- if not source.start then
- return false
- end
return source.start <= offset and source.finish >= offset - 1
end
+--- 判断offset在source的范围内
+function m.isInRange(source, offset)
+ return source.start <= offset and (source.range or source.finish) >= offset - 1
+end
+
--- 遍历所有包含offset的source
function m.eachSource(ast, offset, callback)
local map = m.childMap
@@ -213,8 +224,10 @@ function m.eachSource(ast, offset, callback)
end
local obj = list[len]
list[len] = nil
- if m.isContain(obj, offset) then
- callback(obj)
+ if m.isInRange(obj, offset) then
+ if m.isContain(obj, offset) then
+ callback(obj)
+ end
local keys = map[obj.type]
if keys then
for i = 1, #keys do
@@ -227,10 +240,6 @@ function m.eachSource(ast, offset, callback)
list[#list+1] = obj[key]
end
end
- else
- for i = 1, #obj do
- list[#list+1] = obj[i]
- end
end
end
end