summaryrefslogtreecommitdiff
path: root/script/vm/field.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-31 20:17:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-31 20:17:15 +0800
commit3e516dd717440cad6fce8731a2b627abc6335bbb (patch)
tree39697f19197678af0a8ec6076faa80af01a911f3 /script/vm/field.lua
parent19e1709f0d53975fa0e752cb64c0c47e3c48bedf (diff)
downloadlua-language-server-3e516dd717440cad6fce8731a2b627abc6335bbb.zip
cleanup
Diffstat (limited to 'script/vm/field.lua')
-rw-r--r--script/vm/field.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/script/vm/field.lua b/script/vm/field.lua
new file mode 100644
index 00000000..92448bb3
--- /dev/null
+++ b/script/vm/field.lua
@@ -0,0 +1,45 @@
+---@class vm
+local vm = require 'vm.vm'
+local util = require 'utility'
+local compiler = require 'vm.compiler'
+local guide = require 'parser.guide'
+local localID = require 'vm.local-id'
+local globalMgr = require 'vm.global-manager'
+local nodeMgr = require 'vm.node'
+
+local searchNodeSwitch = util.switch()
+ : case 'table'
+ : call(function (node, pushResult)
+ for _, field in ipairs(node) do
+ if field.type == 'tablefield'
+ or field.type == 'tableindex' then
+ pushResult(field)
+ end
+ end
+ end)
+
+local function searchByNode(source, pushResult)
+ local node = compiler.compileNode(source)
+ if not node then
+ return
+ end
+ searchNodeSwitch(node.type, node, pushResult)
+end
+
+---@param source parser.object
+---@return parser.object[]
+function vm.getFields(source)
+ local results = {}
+ local mark = {}
+
+ local function pushResult(src)
+ if not mark[src] then
+ mark[src] = true
+ results[#results+1] = src
+ end
+ end
+
+ searchByNode(source, pushResult)
+
+ return results
+end