From a86c0e00521835278c85806d61f78838d4283b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 23 Oct 2019 17:46:12 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/searcher/getValue.lua | 2 ++ server-beta/src/searcher/init.lua | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 server-beta/src/searcher/getValue.lua diff --git a/server-beta/src/searcher/getValue.lua b/server-beta/src/searcher/getValue.lua new file mode 100644 index 00000000..5f716b65 --- /dev/null +++ b/server-beta/src/searcher/getValue.lua @@ -0,0 +1,2 @@ +return function () +end diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index 2b85dd24..5a6bc014 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -1,7 +1,9 @@ -local guide = require 'parser.guide' -local files = require 'files' +local guide = require 'parser.guide' +local files = require 'files' +local getValue = require 'searcher.getValue' local setmetatable = setmetatable +local assert = assert _ENV = nil @@ -19,6 +21,28 @@ local specials = { local mt = {} mt.__index = mt mt.__name = 'searcher' +mt._step = 0 + +function mt:step() + self._step = self._step + 1 + assert(self.step <= 100, 'Stack overflow!') + if not self._stepClose then + self._stepClose = setmetatable({}, { + __close = function () + self._step = self._step - 1 + end + }) + end + return self._stepClose +end + +--- 获取关联的值 +---@param source table +---@return value table +function mt:getValue(source) + local _ = self:step() + return getValue(self, source) +end ---@class engineer local m = {} @@ -29,7 +53,6 @@ local m = {} function m.create(uri) local ast = files.getAst(uri) local searcher = setmetatable({ - step = 0, ast = ast.ast, uri = uri, cache = { @@ -39,6 +62,9 @@ function m.create(uri) value = {}, specialName = {}, }, + lock = { + value = {}, + } }, mt) return searcher end -- cgit v1.2.3