diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-03-07 20:49:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-03-07 20:49:20 +0800 |
commit | a31cb772fa4f1da3fd78e4d9f5a01729c22883f7 (patch) | |
tree | 956f02534821541185648a4b784e6faa8f998053 /script/parser | |
parent | f5f0620a09708c07acbb024a0a98bd8595658116 (diff) | |
download | lua-language-server-a31cb772fa4f1da3fd78e4d9f5a01729c22883f7.zip |
update
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/guide.lua | 3 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 106 |
2 files changed, 71 insertions, 38 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 9be84e4e..1d634cbf 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -118,8 +118,9 @@ local childMap = { ['unary'] = {1}, ['doc'] = {'#'}, - ['doc.class'] = {'class', '#extends', 'comment'}, + ['doc.class'] = {'class', '#extends', '#signs', 'comment'}, ['doc.type'] = {'#types', 'name', 'comment'}, + ['doc.type.name'] = {'#signs'}, ['doc.alias'] = {'alias', 'extends', 'comment'}, ['doc.param'] = {'param', 'extends', 'comment'}, ['doc.return'] = {'#returns', 'comment'}, diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 62dff4bd..fbecbb3e 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -122,6 +122,7 @@ Symbol <- ({} { ---@class parser.object ---@field literal boolean +---@field signs parser.object[] local function trim(str) return str:match '^%s*(%S+)%s*$' @@ -306,6 +307,56 @@ local function parseTable(parent) return typeUnit end +local function parseSigns(parent, mode) + if not checkToken('symbol', '<', 1) then + return nil + end + nextToken() + local signs = {} + while true do + local sign + if mode == 'name' then + sign = parseName('doc.generic.name', parent) + if not sign then + pushWarning { + type = 'LUADOC_MISS_SIGN_NAME', + start = getFinish(), + finish = getFinish(), + } + break + end + elseif mode == 'type' then + sign = parseType(parent) + if not sign then + pushWarning { + type = 'LUADOC_MISS_TYPE_NAME', + start = getFinish(), + finish = getFinish(), + } + break + end + end + signs[#signs+1] = sign + if checkToken('symbol', ',', 1) then + nextToken() + else + break + end + end + if not checkToken('symbol', '>', 1) then + pushWarning { + type = 'LUADOC_MISS_SYMBOL', + start = getFinish(), + finish = getFinish(), + symbol = { + symbol = '>', + } + } + end + nextToken() + return signs +end + local function parseClass(parent) local result = { type = 'doc.class', @@ -323,6 +374,7 @@ local function parseClass(parent) end result.start = getStart() result.finish = getFinish() + result.signs = parseSigns(result, 'name') if not checkToken('symbol', ':', 1) then return result end @@ -367,39 +419,6 @@ local function parseTypeUnitArray(parent, node) return result end -local function parseTypeUnitTable(parent, node) - if not checkToken('symbol', '<', 1) then - return nil - end - if not nextSymbolOrError('<') then - return nil - end - - local result = { - type = 'doc.type.table', - start = node.start, - node = node, - parent = parent, - } - - local key = parseType(result) - if not key or not nextSymbolOrError(',') then - return nil - end - local value = parseType(result) - if not value then - return nil - end - nextSymbolOrError('>') - - node.parent = result - result.finish = getFinish() - result.tkey = key - result.tvalue = value - - return result -end - local function parseDots(tp, parent) if not checkToken('symbol', '...', 1) then return @@ -529,6 +548,7 @@ function parseTypeUnit(parent) parent = parent, [1] = token, } + result.signs = parseSigns(result, 'type') end if not result then return nil @@ -1267,14 +1287,26 @@ end local function bindGeneric(binded) local generics = {} for _, doc in ipairs(binded) do - if doc.type == 'doc.generic' then + if doc.type == 'doc.generic' then for _, obj in ipairs(doc.generics) do local name = obj.generic[1] generics[name] = true end - elseif doc.type == 'doc.param' - or doc.type == 'doc.return' - or doc.type == 'doc.type' then + end + if doc.type == 'doc.class' + or doc.type == 'doc.alias' then + if doc.signs then + for _, sign in ipairs(doc.signs) do + local name = sign[1] + generics[name] = true + end + end + end + if doc.type == 'doc.param' + or doc.type == 'doc.return' + or doc.type == 'doc.type' + or doc.type == 'doc.class' + or doc.type == 'doc.alias' then guide.eachSourceType(doc, 'doc.type.name', function (src) local name = src[1] if generics[name] then |