summaryrefslogtreecommitdiff
path: root/server/src/matcher/definition.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/matcher/definition.lua')
-rw-r--r--server/src/matcher/definition.lua93
1 files changed, 87 insertions, 6 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua
index e5ab178d..a4c8fd3d 100644
--- a/server/src/matcher/definition.lua
+++ b/server/src/matcher/definition.lua
@@ -8,7 +8,10 @@ end
function mt:checkName(name)
if self:isContainPos(name) then
- return self.env.var[name]
+ local str = name[1]
+ self.result = self.env.var[str] or self.env.var._ENV[str]
+ self.stop = true
+ return self.result
else
return nil
end
@@ -108,6 +111,71 @@ function mt:checkThenSearchActionsIn(actions)
end
end
+function mt:markSet(simple)
+ if simple.type == 'name' then
+ local str = simple[1]
+ local var = self.env.var[str] -- 是否是一个局部变量?
+ if not var then
+ var = self.env.var._ENV[str] -- 是否是一个全局变量?
+ if not var then
+ -- 创建一个全局变量
+ var = {}
+ self.env.var._ENV[str] = var
+ end
+ end
+ -- 插入赋值信息
+ var[#var+1] = {
+ type = 'set',
+ source = simple,
+ }
+ self:checkName(simple)
+ else
+ self:searchSimple(simple)
+ end
+end
+
+function mt:createLocal(str, type, source)
+ local var = {}
+ self.env.var[str] = var
+ var[1] = {
+ type = type,
+ source = source,
+ }
+end
+
+function mt:markLocal(simple)
+ if simple.type == 'name' then
+ local str = simple[1]
+ -- 创建一个局部变量
+ self:createLocal(str, 'local', simple)
+ self:checkName(simple)
+ else
+ slef:searchSimple(simple)
+ end
+end
+
+function mt:markSets(action)
+ local simples = action[1]
+ if simples.type == 'list' then
+ for _, simple in ipairs(simples) do
+ self:markSet(simple)
+ end
+ else
+ self:markSet(simples)
+ end
+end
+
+function mt:markLocals(action)
+ local simples = action[1]
+ if simple.type == 'list' then
+ for _, simple in ipairs(simples) do
+ self:markLocal(simple)
+ end
+ else
+ self:markLocal(simples)
+ end
+end
+
function mt:searchAction(action)
local tp = action.type
local result
@@ -116,15 +184,21 @@ function mt:searchAction(action)
elseif tp == 'break' then
elseif tp == 'return' then
result = self:searchReturn(action)
+ elseif tp == 'label' then
+ elseif tp == 'goto' then
+ elseif tp == 'set' then
+ self:markSets(action)
+ elseif tp == 'local' then
+ self:markLocals(action)
end
return result
end
function mt:searchActionsIn(actions)
for _, action in ipairs(actions) do
- local result = self:searchAction(action)
- if result then
- return result
+ self:searchAction(action)
+ if self.stop then
+ return self.result
end
end
return nil
@@ -133,8 +207,15 @@ end
return function (ast, pos)
local searcher = setmetatable({
pos = pos,
- env = env {var = {}, usable = {}},
+ env = env {var = {}, usable = {}, label = {}},
}, mt)
+ searcher.env.var._ENV = {}
searcher:searchActionsIn(ast)
- return false
+
+ if not searcher.result then
+ return false
+ end
+
+ local source = searcher.result[1].source
+ return true, source.start, source.finish
end