Module:Module introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
introspection should now ignore strings, on the offchance that strings contain code
Ganaram inukshuk (talk | contribs)
mNo edit summary
Line 70: Line 70:
-- Helper function
-- Helper function
-- Blanks strings while preserving line numbers
-- Blanks strings while preserving line numbers
function p.strip_strings(code)
function p.strip_strings(code_unstripped)
-- Blank double-quoted strings
-- Blank double-quoted strings
code = code:gsub('"(.-)"', function(s)
code_unstripped = code_unstripped:gsub('"(.-)"', function(s)
return string.rep(" ", #s + 2)  -- +2 for the quotes
return string.rep(" ", #s + 2)  -- +2 for the quotes
end)
end)


-- Blank single-quoted strings
-- Blank single-quoted strings
code = code:gsub("'(.-)'", function(s)
code_unstripped = code_unstripped:gsub("'(.-)'", function(s)
return string.rep(" ", #s + 2)
return string.rep(" ", #s + 2)
end)
end)


-- Blank long bracketed strings [[...]]
-- Blank long bracketed strings [[...]]
code = code:gsub("%[%[(.-)%]%]", function(s)
code_unstripped = code_unstripped:gsub("%[%[(.-)%]%]", function(s)
-- Preserve line breaks
-- Preserve line breaks
local blanks = s:gsub(".", " ")
local blanks = s:gsub(".", " ")
Line 89: Line 89:
end)
end)


return code
return code_unstripped
end
end