summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/doc.lua15
-rw-r--r--script/vm/global.lua38
2 files changed, 44 insertions, 9 deletions
diff --git a/script/vm/doc.lua b/script/vm/doc.lua
index 5cb039fe..6ac39910 100644
--- a/script/vm/doc.lua
+++ b/script/vm/doc.lua
@@ -471,3 +471,18 @@ function vm.getCastTargetHead(doc)
end
return nil
end
+
+---@param doc parser.object
+---@param key string
+---@return boolean
+function vm.docHasAttr(doc, key)
+ if not doc.docAttr then
+ return false
+ end
+ for _, name in ipairs(doc.docAttr.names) do
+ if name[1] == key then
+ return true
+ end
+ end
+ return false
+end
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 4e2d0617..e830f6d8 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -372,16 +372,36 @@ local compilerGlobalSwitch = util.switch()
return
end
source._enums = {}
- for _, field in ipairs(tbl) do
- if field.type == 'tablefield' then
- source._enums[#source._enums+1] = field
- local subType = vm.declareGlobal('type', name .. '.' .. field.field[1], uri)
- subType:addSet(uri, field)
- elseif field.type == 'tableindex' then
- source._enums[#source._enums+1] = field
- if field.index.type == 'string' then
- local subType = vm.declareGlobal('type', name .. '.' .. field.index[1], uri)
+ if vm.docHasAttr(source, 'key') then
+ for _, field in ipairs(tbl) do
+ if field.type == 'tablefield' then
+ source._enums[#source._enums+1] = {
+ type = 'doc.type.string',
+ start = field.field.start,
+ finish = field.field.finish,
+ [1] = field.field[1],
+ }
+ elseif field.type == 'tableindex' then
+ source._enums[#source._enums+1] = {
+ type = 'doc.type.string',
+ start = field.index.start,
+ finish = field.index.finish,
+ [1] = field.index[1],
+ }
+ end
+ end
+ else
+ for _, field in ipairs(tbl) do
+ if field.type == 'tablefield' then
+ source._enums[#source._enums+1] = field
+ local subType = vm.declareGlobal('type', name .. '.' .. field.field[1], uri)
subType:addSet(uri, field)
+ elseif field.type == 'tableindex' then
+ source._enums[#source._enums+1] = field
+ if field.index.type == 'string' then
+ local subType = vm.declareGlobal('type', name .. '.' .. field.index[1], uri)
+ subType:addSet(uri, field)
+ end
end
end
end