Module:parameters: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local export = {}
local export = {}
function pattern_escape(pattern_str)
local invoked = false
if type(pattern_str) == "table" then
if pattern_str.args then
local frame = pattern_str
invoked = true
if frame.args[1] then
pattern_str = frame.args[1]
else
pattern_str = frame:getParent().args[1]
end
else
error("First argument to pattern_escape should be a string, a number, or a frame object.")
end
elseif not (type(pattern_str) == "string" or type(pattern_str) == "number") then
error("First argument to pattern_escape should be a string or a number.")
end
if invoked then
local escaped = mw.ustring.gsub(pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1")
return escaped
else
return mw.ustring.gsub(pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1");
end
end


-- A helper function to escape magic characters in a string
-- A helper function to escape magic characters in a string
-- Magic characters: ^$()%.[]*+-?
-- Magic characters: ^$()%.[]*+-?
local plain = pattern_escape
local plain = require("Module:string").pattern_escape


-- A helper function that removes empty numeric indexes in a table,
-- A helper function that removes empty numeric indexes in a table,
Line 49: Line 20:
for name, param in pairs(params) do
for name, param in pairs(params) do
if param.required then
if param.required then
if param.alias_of then
require("Module:debug").track("parameters/required alias")
end
required[name] = true
required[name] = true
end
end
Line 99: Line 73:
--Process required changes to `params`
--Process required changes to `params`
for _, name in ipairs(names_with_equal_sign) do
for _, name in ipairs(names_with_equal_sign) do
require("Module:debug").track("parameters/name with equals")
params[string.gsub(name, "=", "")] = params[name]
params[string.gsub(name, "=", "")] = params[name]
params[name] = nil
params[name] = nil
Line 166: Line 141:
elseif param.type == "number" then
elseif param.type == "number" then
val = tonumber(val)
val = tonumber(val)
elseif param.type then
require("Module:debug").track {
"parameters/unrecognized type",
"parameters/unrecognized type/" .. tostring(param.type)
}
end
end

Navigation menu