Module:Module introspection: Difference between revisions
introspection should now ignore strings, on the offchance that strings contain code |
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( | function p.strip_strings(code_unstripped) | ||
-- Blank double-quoted strings | -- Blank double-quoted strings | ||
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_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_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 | return code_unstripped | ||
end | end | ||