summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/parser/luadoc.lua39
-rw-r--r--test/definition/luadoc.lua15
2 files changed, 53 insertions, 1 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 3a3a0984..10a0b4d7 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -12,7 +12,7 @@ Main <- (Token / Sp)*
Sp <- %s+
X16 <- [a-fA-F0-9]
Word <- [a-zA-Z0-9_]
-Token <- Name / String / Symbol
+Token <- Name / String / Symbol / Index
Name <- ({} {[a-zA-Z0-9_] [a-zA-Z0-9_.*-]*} {})
-> Name
String <- ({} StringDef {})
@@ -50,6 +50,8 @@ Symbol <- ({} {
/ '...'
} {})
-> Symbol
+Index <- ({} '[' Sp? {[0-9]+} Sp? ']' {})
+ -> Index
]], {
s = m.S' \t',
ea = '\a',
@@ -103,6 +105,13 @@ Symbol <- ({} {
TokenFinishs[Ci] = finish - 1
TokenContents[Ci] = content
end,
+ Index = function (start, content, finish)
+ Ci = Ci + 1
+ TokenTypes[Ci] = 'index'
+ TokenStarts[Ci] = start
+ TokenFinishs[Ci] = finish - 1
+ TokenContents[Ci] = content
+ end,
})
local function trim(str)
@@ -180,6 +189,32 @@ local function parseName(tp, parent)
return class
end
+local function parseIndexField(tp, parent)
+ local indexTp, indexText = peekToken()
+ if indexTp ~= 'index' then
+ return nil
+ end
+ nextToken()
+ local int = math.tointeger(indexText)
+ if not int then
+ int = 1
+ -- TODO: translate
+ pushError {
+ type = 'LUADOC_INDEX_MUST_INT',
+ start = getStart(),
+ finish = getFinish(),
+ }
+ end
+ local class = {
+ type = tp,
+ start = getStart(),
+ finish = getFinish(),
+ parent = parent,
+ [1] = int,
+ }
+ return class
+end
+
local function parseClass(parent)
local result = {
type = 'doc.class',
@@ -407,6 +442,7 @@ local function parseTypeUnitLiteralTable()
do
field.name = parseName('doc.field.name', field)
+ or parseIndexField('doc.field.name', field)
if not field.name then
pushError {
type = 'LUADOC_MISS_FIELD_NAME',
@@ -777,6 +813,7 @@ local function parseField()
return false
end)
result.field = parseName('doc.field.name', result)
+ or parseIndexField('doc.field.name', result)
if not result.field then
pushError {
type = 'LUADOC_MISS_FIELD_NAME',
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 34d24cf2..5380f4ca 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -652,3 +652,18 @@ local t
print(t.<?x?>)
]]
+
+TEST [[
+---@class A
+---@field <![1]!>? boolean
+local t
+
+print(t[<?1?>])
+]]
+
+TEST [[
+---@type { <![1]?: boolean!> }
+local t
+
+print(t[<?1?>])
+]]