Module:Module introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
try to bugfix line count again
Ganaram inukshuk (talk | contribs)
fix issue with block comments prematurely halting introspection
Line 17: Line 17:
for line in content:gmatch("([^\n]*)\n") do
for line in content:gmatch("([^\n]*)\n") do
local processed = line
local processed = line
 
if in_multiline then
if in_multiline then
-- inside a multi-line comment: replace everything with spaces
-- check for end of multi-line comment first
processed = processed:gsub(".", " ")
local s, e = processed:find(end_pattern)
-- check for end of multi-line comment
if s then
if processed:find(end_pattern) then
in_multiline = false
in_multiline = false
-- replace only the comment part with spaces
processed = string.rep(" ", e) .. processed:sub(e + 1)
else
-- entire line is inside comment
processed = processed:gsub(".", " ")
end
end
else
else
-- check for start of multi-line comment
local start_eq = processed:match("%-%-%[(=*)%[")
local start_eq = processed:match("%-%-%[(=*)%[")
if start_eq then
if start_eq then
in_multiline = true
in_multiline = true
end_pattern = "%]" .. start_eq .. "%]"
end_pattern = "%]" .. start_eq .. "%]"
processed = processed:gsub(".", " ")
-- blank from the start of comment to the end of line
local s, e = processed:find("%-%-%[" .. start_eq .. "%[")
if s then
processed = string.rep(" ", #processed)
end
else
else
-- replace single-line comments
processed = processed:gsub("%-%-.*", function(s)
processed = processed:gsub("%-%-.*", function(s)
return string.rep(" ", #s)
return string.rep(" ", #s)
Line 39: Line 45:
end
end
end
end
 
table.insert(lines, processed)
end
 
-- handle last line if it doesn’t end with newline
local last_line = content:match("([^\n]+)$")
if last_line then
local processed = last_line
if in_multiline then
processed = processed:gsub(".", " ")
else
processed = processed:gsub("%-%-.*", function(s) return string.rep(" ", #s) end)
end
table.insert(lines, processed)
table.insert(lines, processed)
end
end
Line 172: Line 166:
function p._module_introspection(args)
function p._module_introspection(args)
local args = args or {}
local args = args or {}
local module_name  = args["module_name"  ] or "MOS"
local module_name  = args["module_name"  ] or "Numlinks"
local main_function = args["main_function"]
local main_function = args["main_function"]