diff options
-rw-r--r-- | script/parser/guide.lua | 11 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 32 | ||||
-rw-r--r-- | script/vm/compiler.lua | 28 | ||||
-rw-r--r-- | script/vm/local-id.lua | 5 | ||||
-rw-r--r-- | test/definition/luadoc.lua | 11 |
5 files changed, 59 insertions, 28 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 831534a7..9be84e4e 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -128,12 +128,11 @@ local childMap = { ['doc.generic.object'] = {'generic', 'extends', 'comment'}, ['doc.vararg'] = {'vararg', 'comment'}, ['doc.type.array'] = {'node'}, - ['doc.type.table'] = {'tkey', 'tvalue', 'comment'}, ['doc.type.function'] = {'#args', '#returns', 'comment'}, - ['doc.type.ltable'] = {'#fields', 'comment'}, + ['doc.type.table'] = {'#fields', 'comment'}, ['doc.type.literal'] = {'node'}, ['doc.type.arg'] = {'name', 'extends'}, - ['doc.type.field'] = {'extends'}, + ['doc.type.field'] = {'name', 'extends'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, ['doc.version'] = {'#versions'}, @@ -885,17 +884,17 @@ function m.getKeyNameOfLiteral(obj) elseif tp == 'number' then local n = obj[1] if n then - return formatNumber(obj[1]) + return obj[1] end elseif tp == 'integer' then local n = obj[1] if n then - return formatNumber(obj[1]) + return obj[1] end elseif tp == 'boolean' then local b = obj[1] if b then - return tostring(b) + return b end end end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index ccc38eac..d516643b 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -223,25 +223,24 @@ local function parseIndexField(tp, parent) return nil end nextToken() - local class = { - type = tp, - start = getStart(), - finish = getFinish(), - parent = parent, - } - local indexTP, index = nextToken() - if indexTP ~= 'integer' - and indexTP ~= 'string' then - pushWarning { - type = 'LUADOC_INDEX_MUST_INT', + local indexTP, index = peekToken() + if indexTP == 'name' then + local field = parseType(parent) + nextSymbolOrError ']' + return field + else + nextToken() + local class = { + type = tp, start = getStart(), finish = getFinish(), + parent = parent, } + class[1] = index + nextSymbolOrError ']' + class.finish = getFinish() + return class end - class[1] = index - nextSymbolOrError ']' - class.finish = getFinish() - return class end local function parseClass(parent) @@ -427,7 +426,7 @@ end local function parseTypeUnitLiteralTable() local typeUnit = { - type = 'doc.type.ltable', + type = 'doc.type.table', start = getStart(), fields = {}, } @@ -527,7 +526,6 @@ function parseTypeUnit(parent, content) result.parent = parent while true do local newResult = parseTypeUnitArray(parent, result) - or parseTypeUnitTable(parent, result) if not newResult then break end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index aad5a836..5a6862c9 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -46,6 +46,34 @@ local searchFieldMap = util.switch() end end end) + : case 'doc.type.array' + : call(function (node, key, pushResult) + if type(key) == 'number' + and math.tointeger(key) + and key >= 1 then + pushResult(node.node) + end + end) + : case 'doc.type.table' + : call(function (node, key, pushResult) + for _, field in ipairs(node.fields) do + local fieldKey = field.name + if fieldKey.type == 'doc.type' then + local fieldNode = m.compileNode(fieldKey) + for fn in nodeMgr.eachNode(fieldNode) do + if fn.type == 'global' and fn.cate == 'type' then + if fn.name == 'any' + or (fn.name == 'boolean' and type(key) == 'boolean') + or (fn.name == 'number' and type(key) == 'number') + or (fn.name == 'integer' and math.tointeger(key)) + or (fn.name == 'string' and type(key) == 'string') then + pushResult(field.extends) + end + end + end + end + end + end) : getMap() diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index 230f48eb..3b266916 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -60,7 +60,7 @@ local compileMap = util.switch() return end local key = guide.getKeyName(source) - if not key then + if not type(key) ~= 'string' then return end source._localID = parentID .. m.ID_SPLITE .. key @@ -152,6 +152,9 @@ function m.getSources(source, key) return nil end if key then + if type(key) ~= 'string' then + return nil + end id = id .. m.ID_SPLITE .. key end return root._localIDs[id] diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua index d1a4aaf0..11847898 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -310,12 +310,15 @@ c.<?x?> TEST [[ ---@class A -local <!t!> +local t + +t.<!x!> = 1 ---@type { [number]: A } local b -local <?<!c!>?> = b[1] +local c = b[1] +c.<?x?> ]] TEST [[ @@ -323,7 +326,7 @@ TEST [[ local Foo = {} function Foo:<!bar1!>() end ----@type table<number, Foo> +---@type { [number]: Foo } local v1 print(v1[1].<?bar1?>) ]] @@ -337,7 +340,7 @@ function Foo:<!bar1!>() end local Foo2 = {} function Foo2:bar1() end ----@type Foo2<number, Foo> +---@type { [number]: Foo } local v1 print(v1[1].<?bar1?>) ]] |