summaryrefslogtreecommitdiff
path: root/script/parser/luadoc.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-16 03:32:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-16 03:32:43 +0800
commit1407055930f23b06fbe9a6cc29cc9e54b1356783 (patch)
tree97b65707b0e4a434c9ce9e566453e03e4dfb6176 /script/parser/luadoc.lua
parent8a14323f7da5a4ee5956c417a38a9a85665cf128 (diff)
downloadlua-language-server-1407055930f23b06fbe9a6cc29cc9e54b1356783.zip
fix definition of `table<k, v>`
Diffstat (limited to 'script/parser/luadoc.lua')
-rw-r--r--script/parser/luadoc.lua91
1 files changed, 55 insertions, 36 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 22a2df1b..1d8d7c42 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -309,34 +309,21 @@ local function parseTable(parent)
return typeUnit
end
-local function parseSigns(parent, mode)
+local function parseSigns(parent)
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
+ local sign = parseName('doc.generic.name', parent)
+ if not sign then
+ pushWarning {
+ type = 'LUADOC_MISS_SIGN_NAME',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ break
end
signs[#signs+1] = sign
if checkToken('symbol', ',', 1) then
@@ -345,17 +332,7 @@ local function parseSigns(parent, mode)
break
end
end
- if not checkToken('symbol', '>', 1) then
- pushWarning {
- type = 'LUADOC_MISS_SYMBOL',
- start = getFinish(),
- finish = getFinish(),
- symbol = {
- symbol = '>',
- }
- }
- end
- nextToken()
+ nextSymbolOrError '>'
return signs
end
@@ -376,7 +353,7 @@ local function parseClass(parent)
end
result.start = getStart()
result.finish = getFinish()
- result.signs = parseSigns(result, 'name')
+ result.signs = parseSigns(result)
if not checkToken('symbol', ':', 1) then
return result
end
@@ -421,6 +398,42 @@ local function parseTypeUnitArray(parent, node)
return result
end
+local function parseTypeUnitSign(parent, node)
+ if not checkToken('symbol', '<', 1) then
+ return nil
+ end
+ nextToken()
+ local result = {
+ type = 'doc.type.sign',
+ start = node.start,
+ finish = getFinish(),
+ node = node,
+ parent = parent,
+ signs = {},
+ }
+ node.parent = result
+ while true do
+ local sign = parseType(result)
+ if not sign then
+ pushWarning {
+ type = 'LUA_DOC_MISS_SIGN',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ break
+ end
+ result.signs[#result.signs+1] = sign
+ if checkToken('symbol', ',', 1) then
+ nextToken()
+ else
+ break
+ end
+ end
+ nextSymbolOrError '>'
+ result.finish = getFinish()
+ return result
+end
+
local function parseDots(tp, parent)
if not checkToken('symbol', '...', 1) then
return
@@ -629,7 +642,13 @@ function parseTypeUnit(parent)
result.literal = true
nextSymbolOrError '`'
end
- result.signs = parseSigns(result, 'type')
+ end
+ while true do
+ local newResult = parseTypeUnitSign(parent, result)
+ if not newResult then
+ break
+ end
+ result = newResult
end
while true do
local newResult = parseTypeUnitArray(parent, result)
@@ -777,7 +796,7 @@ local function parseAlias()
return nil
end
result.start = getStart()
- result.signs = parseSigns(result, 'name')
+ result.signs = parseSigns(result)
result.extends = parseType(result)
if not result.extends then
pushWarning {