summaryrefslogtreecommitdiff
path: root/script/parser/luadoc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/parser/luadoc.lua')
-rw-r--r--script/parser/luadoc.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index cd4e76a9..990b4606 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -56,6 +56,7 @@ Symbol <- ({} {
/ '...'
/ '+'
/ '#'
+ / '`'
} {})
-> Symbol
]], {
@@ -450,12 +451,41 @@ function parseType(parent)
if not tp then
break
end
+
+ -- 处理 `T` 的情况
+ local typeLiteral = nil
+ if tp == 'symbol' and content == '`' then
+ nextToken()
+ if not checkToken('symbol', '`', 2) then
+ break
+ end
+ tp, content = peekToken()
+ if not tp then
+ break
+ end
+ -- TypeLiteral,指代类型的字面值。比如,对于类 Cat 来说,它的 TypeLiteral 是 "Cat"
+ typeLiteral = {
+ type = 'doc.type.typeliteral',
+ parent = result,
+ start = getStart(),
+ finish = nil,
+ node = nil,
+ }
+ end
+
if tp == 'name' then
nextToken()
local typeUnit = parseTypeUnit(result, content)
if not typeUnit then
break
end
+ if typeLiteral then
+ nextToken()
+ typeLiteral.finish = getFinish()
+ typeLiteral.node = typeUnit
+ typeUnit.parent = typeLiteral
+ typeUnit = typeLiteral
+ end
result.types[#result.types+1] = typeUnit
if not result.start then
result.start = typeUnit.start