mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(lua2dox): format with stylua
This commit is contained in:
parent
d4e749f1b2
commit
a6d889eae1
@ -132,26 +132,24 @@ function TCore_Clock.getTimeStamp(this,T0)
|
|||||||
return os.date('%c %Z', t0)
|
return os.date('%c %Z', t0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--! \brief write to stdout
|
--! \brief write to stdout
|
||||||
local function TCore_IO_write(Str)
|
local function TCore_IO_write(Str)
|
||||||
if (Str) then
|
if Str then
|
||||||
io.write(Str)
|
io.write(Str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--! \brief write to stdout
|
--! \brief write to stdout
|
||||||
local function TCore_IO_writeln(Str)
|
local function TCore_IO_writeln(Str)
|
||||||
if (Str) then
|
if Str then
|
||||||
io.write(Str)
|
io.write(Str)
|
||||||
end
|
end
|
||||||
io.write("\n")
|
io.write('\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--! \brief trims a string
|
--! \brief trims a string
|
||||||
local function string_trim(Str)
|
local function string_trim(Str)
|
||||||
return Str:match("^%s*(.-)%s*$")
|
return Str:match('^%s*(.-)%s*$')
|
||||||
end
|
end
|
||||||
|
|
||||||
--! \brief split a string
|
--! \brief split a string
|
||||||
@ -162,11 +160,11 @@ end
|
|||||||
---@return string[]
|
---@return string[]
|
||||||
local function string_split(Str, Pattern)
|
local function string_split(Str, Pattern)
|
||||||
local splitStr = {}
|
local splitStr = {}
|
||||||
local fpat = "(.-)" .. Pattern
|
local fpat = '(.-)' .. Pattern
|
||||||
local last_end = 1
|
local last_end = 1
|
||||||
local str, e, cap = string.find(Str, fpat, 1)
|
local str, e, cap = string.find(Str, fpat, 1)
|
||||||
while str do
|
while str do
|
||||||
if str ~= 1 or cap ~= "" then
|
if str ~= 1 or cap ~= '' then
|
||||||
table.insert(splitStr, cap)
|
table.insert(splitStr, cap)
|
||||||
end
|
end
|
||||||
last_end = e + 1
|
last_end = e + 1
|
||||||
@ -179,7 +177,6 @@ local function string_split(Str, Pattern)
|
|||||||
return splitStr
|
return splitStr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--! \class TCore_Commandline
|
--! \class TCore_Commandline
|
||||||
--! \brief reads/parses commandline
|
--! \brief reads/parses commandline
|
||||||
local TCore_Commandline = class()
|
local TCore_Commandline = class()
|
||||||
@ -371,7 +368,7 @@ local function checkComment4fn(Fn_magic,MagicLines)
|
|||||||
return fn_magic
|
return fn_magic
|
||||||
end
|
end
|
||||||
|
|
||||||
local types = {"number", "string", "table", "list", "boolean", "function"}
|
local types = { 'number', 'string', 'table', 'list', 'boolean', 'function' }
|
||||||
|
|
||||||
--! \brief run the filter
|
--! \brief run the filter
|
||||||
function TLua2DoX_filter.readfile(this, AppStamp, Filename)
|
function TLua2DoX_filter.readfile(this, AppStamp, Filename)
|
||||||
@ -379,7 +376,7 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename)
|
|||||||
local outStream = TStream_Write()
|
local outStream = TStream_Write()
|
||||||
this.outStream = outStream -- save to this obj
|
this.outStream = outStream -- save to this obj
|
||||||
|
|
||||||
if (inStream:getContents(Filename)) then
|
if inStream:getContents(Filename) then
|
||||||
-- output the file
|
-- output the file
|
||||||
local line
|
local line
|
||||||
local fn_magic -- function name/def from magic comment
|
local fn_magic -- function name/def from magic comment
|
||||||
@ -414,22 +411,23 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename)
|
|||||||
local magic_split = string_split(magic, ' ')
|
local magic_split = string_split(magic, ' ')
|
||||||
if magic_split[1] == 'param' then
|
if magic_split[1] == 'param' then
|
||||||
for _, type in ipairs(types) do
|
for _, type in ipairs(types) do
|
||||||
magic = magic:gsub("^param%s+([a-zA-Z_?]+)%s+.*%((" .. type .. ")%)", "param %1 %2" )
|
magic = magic:gsub('^param%s+([a-zA-Z_?]+)%s+.*%((' .. type .. ')%)', 'param %1 %2')
|
||||||
magic = magic:gsub("^param%s+([a-zA-Z_?]+)%s+.*%((" .. type .. "|nil)%)", "param %1 %2" )
|
magic =
|
||||||
|
magic:gsub('^param%s+([a-zA-Z_?]+)%s+.*%((' .. type .. '|nil)%)', 'param %1 %2')
|
||||||
end
|
end
|
||||||
magic_split = string_split(magic, ' ')
|
magic_split = string_split(magic, ' ')
|
||||||
elseif magic_split[1] == 'return' then
|
elseif magic_split[1] == 'return' then
|
||||||
for _, type in ipairs(types) do
|
for _, type in ipairs(types) do
|
||||||
magic = magic:gsub("^return%s+.*%((" .. type .. ")%)", "return %1" )
|
magic = magic:gsub('^return%s+.*%((' .. type .. ')%)', 'return %1')
|
||||||
magic = magic:gsub("^return%s+.*%((" .. type .. "|nil)%)", "return %1" )
|
magic = magic:gsub('^return%s+.*%((' .. type .. '|nil)%)', 'return %1')
|
||||||
end
|
end
|
||||||
magic_split = string_split(magic, ' ')
|
magic_split = string_split(magic, ' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
if magic_split[1] == "generic" then
|
if magic_split[1] == 'generic' then
|
||||||
local generic_name, generic_type = line:match("@generic%s*(%w+)%s*:?%s*(.*)")
|
local generic_name, generic_type = line:match('@generic%s*(%w+)%s*:?%s*(.*)')
|
||||||
if generic_type == "" then
|
if generic_type == '' then
|
||||||
generic_type = "any"
|
generic_type = 'any'
|
||||||
end
|
end
|
||||||
generic[generic_name] = generic_type
|
generic[generic_name] = generic_type
|
||||||
else
|
else
|
||||||
@ -440,9 +438,9 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename)
|
|||||||
|
|
||||||
if magic_split[type_index] then
|
if magic_split[type_index] then
|
||||||
-- fix optional parameters
|
-- fix optional parameters
|
||||||
if magic_split[type_index] and magic_split[2]:find("%?$") then
|
if magic_split[type_index] and magic_split[2]:find('%?$') then
|
||||||
if not magic_split[type_index]:find("nil") then
|
if not magic_split[type_index]:find('nil') then
|
||||||
magic_split[type_index] = magic_split[type_index] .. "|nil"
|
magic_split[type_index] = magic_split[type_index] .. '|nil'
|
||||||
end
|
end
|
||||||
magic_split[2] = magic_split[2]:sub(1, -2)
|
magic_split[2] = magic_split[2]:sub(1, -2)
|
||||||
end
|
end
|
||||||
@ -454,8 +452,10 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename)
|
|||||||
end
|
end
|
||||||
-- surround some types by ()
|
-- surround some types by ()
|
||||||
for _, type in ipairs(types) do
|
for _, type in ipairs(types) do
|
||||||
magic_split[type_index] = magic_split[type_index]:gsub("^(" .. type .. "|nil):?$", "(%1)")
|
magic_split[type_index] =
|
||||||
magic_split[type_index] = magic_split[type_index]:gsub("^(" .. type .. "):?$", "(%1)")
|
magic_split[type_index]:gsub('^(' .. type .. '|nil):?$', '(%1)')
|
||||||
|
magic_split[type_index] =
|
||||||
|
magic_split[type_index]:gsub('^(' .. type .. '):?$', '(%1)')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -471,7 +471,7 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename)
|
|||||||
line = string.sub(line, 5) -- nibble head
|
line = string.sub(line, 5) -- nibble head
|
||||||
local comment = ''
|
local comment = ''
|
||||||
local closeSquare, hitend, thisComment
|
local closeSquare, hitend, thisComment
|
||||||
while (not hitend) and (not inStream:eof()) do
|
while not hitend and (not inStream:eof()) do
|
||||||
closeSquare = string.find(line, ']]')
|
closeSquare = string.find(line, ']]')
|
||||||
if not closeSquare then -- need to look on another line
|
if not closeSquare then -- need to look on another line
|
||||||
thisComment = line .. '\n'
|
thisComment = line .. '\n'
|
||||||
@ -537,24 +537,27 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Big hax
|
-- Big hax
|
||||||
if string.find(fn, ":") then
|
if string.find(fn, ':') then
|
||||||
-- TODO: We need to add a first parameter of "SELF" here
|
-- TODO: We need to add a first parameter of "SELF" here
|
||||||
-- local colon_place = string.find(fn, ":")
|
-- local colon_place = string.find(fn, ":")
|
||||||
-- local name = string.sub(fn, 1, colon_place)
|
-- local name = string.sub(fn, 1, colon_place)
|
||||||
fn = fn:gsub(":", ".", 1)
|
fn = fn:gsub(':', '.', 1)
|
||||||
outStream:writeln("/// @param self")
|
outStream:writeln('/// @param self')
|
||||||
|
|
||||||
local paren_start = string.find(fn, "(", 1, true)
|
local paren_start = string.find(fn, '(', 1, true)
|
||||||
local paren_finish = string.find(fn, ")", 1, true)
|
local paren_finish = string.find(fn, ')', 1, true)
|
||||||
|
|
||||||
-- Nothing in between the parens
|
-- Nothing in between the parens
|
||||||
local comma
|
local comma
|
||||||
if paren_finish == paren_start + 1 then
|
if paren_finish == paren_start + 1 then
|
||||||
comma = ""
|
comma = ''
|
||||||
else
|
else
|
||||||
comma = ", "
|
comma = ', '
|
||||||
end
|
end
|
||||||
fn = string.sub(fn, 1, paren_start) .. "self" .. comma .. string.sub(fn, paren_start + 1)
|
fn = string.sub(fn, 1, paren_start)
|
||||||
|
.. 'self'
|
||||||
|
.. comma
|
||||||
|
.. string.sub(fn, paren_start + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add vanilla function
|
-- add vanilla function
|
||||||
@ -601,8 +604,7 @@ function TApp.init(this)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function TApp.getRunStamp(this)
|
function TApp.getRunStamp(this)
|
||||||
return this.name .. ' (' .. this.version .. ') '
|
return this.name .. ' (' .. this.version .. ') ' .. this.timestamp
|
||||||
.. this.timestamp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function TApp.getVersion(this)
|
function TApp.getVersion(this)
|
||||||
@ -642,5 +644,4 @@ else
|
|||||||
filter:readfile(appStamp, filename)
|
filter:readfile(appStamp, filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--eof
|
--eof
|
||||||
|
Loading…
Reference in New Issue
Block a user