1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
local guide = require 'parser.guide'
local files = require 'files'
local getValue = require 'searcher.getValue'
local setmetatable = setmetatable
local assert = assert
_ENV = nil
local specials = {
['_G'] = true,
['rawset'] = true,
['rawget'] = true,
['setmetatable'] = true,
['require'] = true,
['dofile'] = true,
['loadfile'] = true,
}
---@class searcher
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 _ <close> = self:step()
return getValue(self, source)
end
---@class engineer
local m = {}
--- 新建搜索器
---@param uri string
---@return searcher
function m.create(uri)
local ast = files.getAst(uri)
local searcher = setmetatable({
ast = ast.ast,
uri = uri,
cache = {
def = {},
ref = {},
field = {},
value = {},
specialName = {},
},
lock = {
value = {},
}
}, mt)
return searcher
end
return m
|