Skip to content

Commit 94a1cef

Browse files
committed
cleanup
1 parent 8f94bf9 commit 94a1cef

File tree

1 file changed

+89
-87
lines changed

1 file changed

+89
-87
lines changed

script/parser/luadoc.lua

Lines changed: 89 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ local function bindDocs(state)
19581958
binded = {}
19591959
state.ast.docs.groups[#state.ast.docs.groups+1] = binded
19601960
end
1961-
binded[#binded+1] = doc
1961+
binded[#binded+1] = doc
19621962
if isTailComment(text, doc) then
19631963
bindDocWithSources(sources, binded)
19641964
binded = nil
@@ -1994,105 +1994,107 @@ local function findTouch(state, doc)
19941994
end
19951995
end
19961996

1997-
return {
1998-
buildAndBindDoc = function (ast, src, comment)
1999-
local doc = buildLuaDoc(comment)
2000-
if doc then
2001-
local pluginDocs = ast.state.pluginDocs or {}
2002-
pluginDocs[#pluginDocs+1] = doc
2003-
doc.special = src
2004-
doc.originalComment = comment
2005-
ast.state.pluginDocs = pluginDocs
2006-
return true
2007-
end
2008-
return false
2009-
end,
2010-
luadoc = function (state)
2011-
local ast = state.ast
2012-
local comments = state.comms
2013-
table.sort(comments, function (a, b)
2014-
return a.start < b.start
2015-
end)
2016-
ast.docs = {
2017-
type = 'doc',
2018-
parent = ast,
2019-
groups = {},
2020-
}
1997+
local function luadoc(state)
1998+
local ast = state.ast
1999+
local comments = state.comms
2000+
table.sort(comments, function (a, b)
2001+
return a.start < b.start
2002+
end)
2003+
ast.docs = {
2004+
type = 'doc',
2005+
parent = ast,
2006+
groups = {},
2007+
}
20212008

2022-
pushWarning = function (err)
2023-
local errs = state.errs
2024-
if err.finish < err.start then
2025-
err.finish = err.start
2026-
end
2027-
local last = errs[#errs]
2028-
if last then
2029-
if last.start <= err.start and last.finish >= err.finish then
2030-
return
2031-
end
2009+
pushWarning = function (err)
2010+
local errs = state.errs
2011+
if err.finish < err.start then
2012+
err.finish = err.start
2013+
end
2014+
local last = errs[#errs]
2015+
if last then
2016+
if last.start <= err.start and last.finish >= err.finish then
2017+
return
20322018
end
2033-
err.level = err.level or 'Warning'
2034-
errs[#errs+1] = err
2035-
return err
20362019
end
2037-
Lines = state.lines
2020+
err.level = err.level or 'Warning'
2021+
errs[#errs+1] = err
2022+
return err
2023+
end
2024+
Lines = state.lines
20382025

2039-
local ci = 1
2040-
NextComment = function (offset, peek)
2041-
local comment = comments[ci + (offset or 0)]
2042-
if not peek then
2043-
ci = ci + 1 + (offset or 0)
2044-
end
2045-
return comment
2026+
local ci = 1
2027+
NextComment = function (offset, peek)
2028+
local comment = comments[ci + (offset or 0)]
2029+
if not peek then
2030+
ci = ci + 1 + (offset or 0)
20462031
end
2032+
return comment
2033+
end
20472034

2048-
local function insertDoc(doc, comment)
2049-
ast.docs[#ast.docs+1] = doc
2050-
doc.parent = ast.docs
2051-
if ast.start > doc.start then
2052-
ast.start = doc.start
2053-
end
2054-
if ast.finish < doc.finish then
2055-
ast.finish = doc.finish
2056-
end
2057-
doc.originalComment = comment
2058-
if comment.type == 'comment.long' then
2059-
findTouch(state, doc)
2060-
end
2035+
local function insertDoc(doc, comment)
2036+
ast.docs[#ast.docs+1] = doc
2037+
doc.parent = ast.docs
2038+
if ast.start > doc.start then
2039+
ast.start = doc.start
2040+
end
2041+
if ast.finish < doc.finish then
2042+
ast.finish = doc.finish
2043+
end
2044+
doc.originalComment = comment
2045+
if comment.type == 'comment.long' then
2046+
findTouch(state, doc)
20612047
end
2048+
end
20622049

2063-
while true do
2064-
local comment = NextComment()
2065-
if not comment then
2066-
break
2067-
end
2068-
lockResume = false
2069-
local doc, rests = buildLuaDoc(comment)
2070-
if doc then
2071-
insertDoc(doc, comment)
2072-
if rests then
2073-
for _, rest in ipairs(rests) do
2074-
insertDoc(rest, comment)
2075-
end
2050+
while true do
2051+
local comment = NextComment()
2052+
if not comment then
2053+
break
2054+
end
2055+
lockResume = false
2056+
local doc, rests = buildLuaDoc(comment)
2057+
if doc then
2058+
insertDoc(doc, comment)
2059+
if rests then
2060+
for _, rest in ipairs(rests) do
2061+
insertDoc(rest, comment)
20762062
end
20772063
end
20782064
end
2079-
2080-
if ast.state.pluginDocs then
2081-
for i, doc in ipairs(ast.state.pluginDocs) do
2082-
insertDoc(doc, doc.originalComment)
2083-
end
2084-
table.sort(ast.docs, function (a, b)
2085-
return a.start < b.start
2086-
end)
2065+
end
2066+
2067+
if ast.state.pluginDocs then
2068+
for i, doc in ipairs(ast.state.pluginDocs) do
2069+
insertDoc(doc, doc.originalComment)
20872070
end
2071+
table.sort(ast.docs, function (a, b)
2072+
return a.start < b.start
2073+
end)
2074+
end
20882075

2089-
ast.docs.start = ast.start
2090-
ast.docs.finish = ast.finish
2091-
2092-
if #ast.docs == 0 then
2093-
return
2094-
end
2076+
ast.docs.start = ast.start
2077+
ast.docs.finish = ast.finish
20952078

2096-
bindDocs(state)
2079+
if #ast.docs == 0 then
2080+
return
20972081
end
2082+
2083+
bindDocs(state)
2084+
end
2085+
2086+
return {
2087+
buildAndBindDoc = function (ast, src, comment)
2088+
local doc = buildLuaDoc(comment)
2089+
if doc then
2090+
local pluginDocs = ast.state.pluginDocs or {}
2091+
pluginDocs[#pluginDocs+1] = doc
2092+
doc.special = src
2093+
doc.originalComment = comment
2094+
ast.state.pluginDocs = pluginDocs
2095+
return true
2096+
end
2097+
return false
2098+
end,
2099+
luadoc = luadoc
20982100
}

0 commit comments

Comments
 (0)