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.lua65
1 files changed, 54 insertions, 11 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 9f3b8fd5..8e7d334f 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -156,6 +156,7 @@ Symbol <- ({} {
---@field calls? parser.object[]
---@field generics? parser.object[]
---@field generic? parser.object
+---@field docAttr? parser.object
local function parseTokens(text, offset)
Ci = 0
@@ -252,6 +253,40 @@ local function nextSymbolOrError(symbol)
return false
end
+local function parseDocAttr(parent)
+ if not checkToken('symbol', '(', 1) then
+ return nil
+ end
+ nextToken()
+
+ local attrs = {
+ type = 'doc.attr',
+ parent = parent,
+ start = getStart(),
+ finish = getStart(),
+ names = {},
+ }
+
+ while true do
+ if checkToken('symbol', ',', 1) then
+ nextToken()
+ goto continue
+ end
+ local name = parseName('doc.attr.name', attrs)
+ if not name then
+ break
+ end
+ attrs.names[#attrs.names+1] = name
+ attrs.finish = name.finish
+ ::continue::
+ end
+
+ nextSymbolOrError(')')
+ attrs.finish = getFinish()
+
+ return attrs
+end
+
local function parseIndexField(parent)
if not checkToken('symbol', '[', 1) then
return nil
@@ -806,6 +841,7 @@ local docSwitch = util.switch()
operators = {},
calls = {},
}
+ result.docAttr = parseDocAttr(result)
result.class = parseName('doc.class.name', result)
if not result.class then
pushWarning {
@@ -1108,13 +1144,13 @@ local docSwitch = util.switch()
end)
: case 'meta'
: call(function ()
- local requireName = parseName('doc.meta.name')
- return {
+ local meta = {
type = 'doc.meta',
- name = requireName,
start = getFinish(),
finish = getFinish(),
}
+ meta.name = parseName('doc.meta.name', meta)
+ return meta
end)
: case 'version'
: call(function ()
@@ -1428,17 +1464,22 @@ local docSwitch = util.switch()
end)
: case 'enum'
: call(function ()
+ local attr = parseDocAttr()
local name = parseName('doc.enum.name')
if not name then
return nil
end
local result = {
- type = 'doc.enum',
- start = name.start,
- finish = name.finish,
- enum = name,
+ type = 'doc.enum',
+ start = name.start,
+ finish = name.finish,
+ enum = name,
+ docAttr = attr,
}
name.parent = result
+ if attr then
+ attr.parent = result
+ end
return result
end)
: case 'private'
@@ -1534,7 +1575,7 @@ local function buildLuaDoc(comment)
parseTokens(doc, startOffset + startPos)
local result, rests = convertTokens(doc)
if result then
- result.range = comment.finish
+ result.range = math.max(comment.finish, result.finish)
local finish = result.firstFinish or result.finish
if rests then
for _, rest in ipairs(rests) do
@@ -1669,7 +1710,9 @@ local function bindDocWithSource(doc, source)
if not source.bindDocs then
source.bindDocs = {}
end
- source.bindDocs[#source.bindDocs+1] = doc
+ if source.bindDocs[#source.bindDocs] ~= doc then
+ source.bindDocs[#source.bindDocs+1] = doc
+ end
doc.bindSource = source
end
@@ -1820,7 +1863,7 @@ local function bindDocsBetween(sources, binded, start, finish)
or src.type == 'setindex'
or src.type == 'setmethod'
or src.type == 'function'
- or src.type == 'table'
+ or src.type == 'return'
or src.type == '...' then
if bindDoc(src, binded) then
ok = true
@@ -1940,7 +1983,7 @@ local bindDocAccept = {
'local' , 'setlocal' , 'setglobal',
'setfield' , 'setmethod' , 'setindex' ,
'tablefield', 'tableindex', 'self' ,
- 'function' , 'table' , '...' ,
+ 'function' , 'return' , '...' ,
}
local function bindDocs(state)