Module:Params: Difference between revisions

PS (talk | contribs)
m 1 revision imported
en>Grufo
bugfix
Line 1: Line 1:
require[[strict]]
---                                        ---
---                                        ---
---    LOCAL ENVIRONMENT                  ---
---    LOCAL ENVIRONMENT                  ---
Line 26: Line 29:
local function copy_or_ref_table (src, refonly)
local function copy_or_ref_table (src, refonly)
if refonly then return src end
if refonly then return src end
newtab = {}
local newtab = {}
for key, val in pairs(src) do newtab[key] = val end
for key, val in pairs(src) do newtab[key] = val end
return newtab
return newtab
Line 237: Line 240:
concat_and_invoke = true,
concat_and_invoke = true,
concat_and_magic = true,
concat_and_magic = true,
converting_names_to_uppercase = true,
converting_names_to_lowercase = true,
count = true,
count = true,
--inserting = true,
--inserting = true,
grouping_by_calling = true,
grouping_by_calling = true,
mixing_names_and_values = true,
renaming_by_mixing = true,
--renaming_to_values = true,
--swapping_names_and_values = true,
value_of = true,
value_of = true,
with_name_matching = true
with_name_matching = true
Line 399: Line 408:
if flg ~= nil then flg = mkeywords[flg:match'^%s*(.-)%s*$'] end
if flg ~= nil then flg = mkeywords[flg:match'^%s*(.-)%s*$'] end
if flg == 0 then flg = nil elseif flg ~= nil then argc = argc + 1 end
if flg == 0 then flg = nil elseif flg ~= nil then argc = argc + 1 end
return ptn, repl, nmax, flg == 3, argc, (nmax ~= nil and nmax < 1) or
return ptn, repl, nmax, flg, argc, (nmax ~= nil and nmax < 1) or
(flg == 3 and ptn == repl)
(flg == 3 and ptn == repl)
end
end
Line 502: Line 511:


-- Private table for `map_names()`
-- Private table for `map_names()`
local name_thieves_maps = {
local name_thieves = {
[0] = function (cache, tbl, rargs, karg, varg, fn)
[0] = function (cache, tbl, rargs, karg, varg, fn)
for key, val in pairs(tbl) do
for key, val in pairs(tbl) do
Line 533: Line 542:
local function map_names (tbl, rargs, karg, varg, looptype, fn)
local function map_names (tbl, rargs, karg, varg, looptype, fn)
local cache = {}
local cache = {}
name_thieves_maps[looptype](cache, tbl, rargs, karg, varg, fn)
name_thieves[looptype](cache, tbl, rargs, karg, varg, fn)
for key, val in pairs(cache) do tbl[key] = val end
for key, val in pairs(cache) do tbl[key] = val end
end
end
Line 561: Line 570:
end
end
return groups
return groups
end
-- Split into parts a string containing the `$#` and `$@` placeholders and
-- return the information as a skeleton table, a canvas table and a length
local function parse_placeholder_string (target)
local skel = {}
local canvas = {}
local idx = 1
local s_pos = 1
local e_pos = string.find(target, '%$[@#]', 1, false)
while e_pos ~= nil do
canvas[idx] = target:sub(s_pos, e_pos - 1)
skel[idx + 1] = target:sub(e_pos, e_pos + 1) == '$@'
idx = idx + 2
s_pos = e_pos + 2
e_pos = string.find(target, '%$[@#]', s_pos, false)
end
if (s_pos > target:len()) then idx = idx - 1
else canvas[idx] = target:sub(s_pos) end
return skel, canvas, idx
end
end


Line 973: Line 1,003:




-- Syntax:  #invoke:params|rotating|pipe to
-- Syntax:  #invoke:params|reversing_numeric_names|pipe to
library.rotating = function (ctx)
library.reversing_numeric_names = function (ctx)
local tbl = ctx.params
local tbl = ctx.params
local numerics = {}
local numerics = {}
Line 990: Line 1,020:




-- Syntax:  #invoke:params|pivoting|pipe to
-- Syntax:  #invoke:params|pivoting_numeric_names|pipe to
--[[
--[[
library.pivoting = function (ctx)
library.pivoting_numeric_names = function (ctx)
local tbl = ctx.params
local tbl = ctx.params
local shift = #tbl + 1
local shift = #tbl + 1
if shift < 2 then return library.rotating(ctx) end
if shift < 2 then return library.reversing_numeric_names(ctx) end
local numerics = {}
local numerics = {}
for key, val in pairs(tbl) do
for key, val in pairs(tbl) do
Line 1,009: Line 1,039:




-- Syntax:  #invoke:params|mirroring|pipe to
-- Syntax:  #invoke:params|mirroring_numeric_names|pipe to
--[[
--[[
library.mirroring = function (ctx)
library.mirroring_numeric_names = function (ctx)
local tbl = ctx.params
local tbl = ctx.params
local numerics = {}
local numerics = {}
Line 1,033: Line 1,063:




-- Syntax:  #invoke:params|swapping|pipe to
-- Syntax:  #invoke:params|swapping_numeric_names|pipe to
--[[
--[[
library.swapping = function (ctx)
library.swapping_numeric_names = function (ctx)
local tbl = ctx.params
local tbl = ctx.params
local cache = {}
local cache = {}
Line 1,155: Line 1,185:
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- this function MUST create a copy of it before returning
-- this function MUST create a copy of it before returning
local targets, nptns, argc = load_pattern_args(ctx.pipe, targets,
local targets, nptns, argc = load_pattern_args(ctx.pipe,
'with_name_matching')
'with_name_matching')
local tmp
local tmp
Line 1,183: Line 1,213:
--            flag N]|pipe to
--            flag N]|pipe to
library.with_name_not_matching = function (ctx)
library.with_name_not_matching = function (ctx)
local targets, nptns, argc = load_pattern_args(ctx.pipe, targets,
local targets, nptns, argc = load_pattern_args(ctx.pipe,
'with_name_not_matching')
'with_name_not_matching')
local tbl = ctx.params
local tbl = ctx.params
Line 1,218: Line 1,248:
library.with_value_matching = function (ctx)
library.with_value_matching = function (ctx)
local tbl = ctx.params
local tbl = ctx.params
local targets, nptns, argc = load_pattern_args(ctx.pipe, targets,
local targets, nptns, argc = load_pattern_args(ctx.pipe,
'with_value_matching')
'with_value_matching')
local nomatch
local nomatch
Line 1,247: Line 1,277:
library.with_value_not_matching = function (ctx)
library.with_value_not_matching = function (ctx)
local tbl = ctx.params
local tbl = ctx.params
local targets, nptns, argc = load_pattern_args(ctx.pipe, targets,
local targets, nptns, argc = load_pattern_args(ctx.pipe,
'with_value_not_matching')
'with_value_not_matching')
local yesmatch
local yesmatch
Line 1,275: Line 1,305:
local tbl = ctx.params
local tbl = ctx.params
for key, val in pairs(tbl) do tbl[key] = val:match'^%s*(.-)%s*$' end
for key, val in pairs(tbl) do tbl[key] = val:match'^%s*(.-)%s*$' end
return context_iterate(ctx, 1)
end
-- Syntax:  #invoke:params|converting_values_to_lowercase|pipe to
library.converting_values_to_lowercase = function (ctx)
local tbl = ctx.params
for key, val in pairs(tbl) do tbl[key] = val:lower() end
return context_iterate(ctx, 1)
end
-- Syntax:  #invoke:params|converting_values_to_uppercase|pipe to
library.converting_values_to_uppercase = function (ctx)
local tbl = ctx.params
for key, val in pairs(tbl) do tbl[key] = val:upper() end
return context_iterate(ctx, 1)
return context_iterate(ctx, 1)
end
end
Line 1,346: Line 1,392:
--            flag]|pipe to
--            flag]|pipe to
library.mapping_by_replacing = function (ctx)
library.mapping_by_replacing = function (ctx)
local ptn, repl, nmax, is_strict, argc, die =
local ptn, repl, nmax, flg, argc, die =
load_replace_args(ctx.pipe, 'mapping_by_replacing')
load_replace_args(ctx.pipe, 'mapping_by_replacing')
if die then return context_iterate(ctx, argc) end
if die then return context_iterate(ctx, argc) end
local tbl = ctx.params
local tbl = ctx.params
if is_strict then
if flg == 3 then
for key, val in pairs(tbl) do
for key, val in pairs(tbl) do
if val == ptn then tbl[key] = repl end
if val == ptn then tbl[key] = repl end
Line 1,367: Line 1,413:




-- Syntax:  #invoke:params|renaming_by_calling|template name|[call
-- Syntax:  #invoke:params|mapping_by_mixing|mixing string|pipe to
--            style]|[let]|[...][number of additional parameters]|[parameter
library.mapping_by_mixing = function (ctx)
--            1]|[parameter 2]|[...]|[parameter N]|pipe to
if ctx.pipe[1] == nil then error(modulename ..
library.renaming_by_calling = function (ctx)
', ‘mapping_by_mixing’: No mixing string was provided', 0) end
local opts = ctx.pipe
local mix = ctx.pipe[1]
local tname
local tbl = ctx.params
if opts[1] ~= nil then tname = opts[1]:match'^%s*(.*%S)' end
if mix == '$#' then
if tname == nil then error(modulename ..
for key in pairs(tbl) do tbl[key] = key end
', ‘renaming_by_calling’: No template name was provided', 0) end
return context_iterate(ctx, 2)
local rargs, argc, looptype, karg, varg = load_callback_opts(opts, 1,
end
mapping_styles.names_only)
local skel, cnv, n_parts = parse_placeholder_string(mix)
local model = { title = tname, args = rargs }
for key, val in pairs(tbl) do
map_names(ctx.params, rargs, karg, varg, looptype, function ()
for idx = 2, n_parts, 2 do
return ctx.frame:expandTemplate(model)
if skel[idx] then cnv[idx] = val else cnv[idx] = tostring(key) end
end)
end
return context_iterate(ctx, argc)
tbl[key] = table.concat(cnv)
end
return context_iterate(ctx, 2)
end
 
 
-- Syntax:  #invoke:params|mapping_to_names|pipe to
--[[
library.mapping_to_names = function (ctx)
local tbl = ctx.params
for key in pairs(tbl) do tbl[key] = key end
return context_iterate(ctx, 1)
end
end
]]--




-- Syntax:  #invoke:params|renaming_by_invoking|module name|function
-- Syntax:  #invoke:params|converting_names_to_lowercase|pipe to
--            name|[call style]|[let]|[...]|[number of additional
library.converting_names_to_lowercase = function (ctx)
--            arguments]|[argument 1]|[argument 2]|[...]|[argument N]|pipe to
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
library.renaming_by_invoking = function (ctx)
-- this function MUST create a copy of it before returning
local opts = ctx.pipe
local cache = {}
local mname
for key, val in pairs(ctx.params) do
local fname
if type(key) == 'string' then cache[key:lower()] = val else
if opts[1] ~= nil then mname = opts[1]:match'^%s*(.*%S)' end
cache[key] = val end
if mname == nil then error(modulename ..
end
', ‘renaming_by_invoking’: No module name was provided', 0) end
ctx.params = cache
if opts[2] ~= nil then fname = opts[2]:match'^%s*(.*%S)' end
return context_iterate(ctx, 1)
if fname == nil then error(modulename ..
end
', ‘renaming_by_invoking’: No function name was provided', 0) end
 
local rargs, argc, looptype, karg, varg = load_callback_opts(opts, 2,
 
mapping_styles.names_only)
-- Syntax:  #invoke:params|converting_names_to_uppercase|pipe to
local model = { title = 'Module:' .. mname, args = rargs }
library.converting_names_to_uppercase = function (ctx)
local mfunc = require(model.title)[fname]
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
if mfunc == nil then error(modulename ..
-- this function MUST create a copy of it before returning
', ‘renaming_by_invoking’: The function ‘' .. fname ..
local cache = {}
'’ does not exist', 0) end
for key, val in pairs(ctx.params) do
map_names(ctx.params, rargs, karg, varg, looptype, function ()
if type(key) == 'string' then cache[key:upper()] = val else
local tmp = mfunc(ctx.frame:newChild(model))
cache[key] = val end
return tonumber(tmp) or tostring(tmp)
end
end)
ctx.params = cache
return context_iterate(ctx, argc)
return context_iterate(ctx, 1)
end
end




-- Syntax:  #invoke:params|renaming_by_magic|parser function|[call
-- Syntax:  #invoke:params|renaming_by_calling|template name|[call
--            style]|[let]|[...][number of additional arguments]|[argument
--            style]|[let]|[...][number of additional parameters]|[parameter
--            1]|[argument 2]|[...]|[argument N]|pipe to
--            1]|[parameter 2]|[...]|[parameter N]|pipe to
library.renaming_by_magic = function (ctx)
library.renaming_by_calling = function (ctx)
local opts = ctx.pipe
local opts = ctx.pipe
local magic
local tname
if opts[1] ~= nil then magic = opts[1]:match'^%s*(.*%S)' end
if opts[1] ~= nil then tname = opts[1]:match'^%s*(.*%S)' end
if magic == nil then error(modulename ..
if tname == nil then error(modulename ..
', ‘renaming_by_magic’: No parser function was provided', 0) end
', ‘renaming_by_calling’: No template name was provided', 0) end
local rargs, argc, looptype, karg, varg = load_callback_opts(opts, 1,
local rargs, argc, looptype, karg, varg = load_callback_opts(opts, 1,
mapping_styles.names_only)
mapping_styles.names_only)
local model = { title = tname, args = rargs }
map_names(ctx.params, rargs, karg, varg, looptype, function ()
map_names(ctx.params, rargs, karg, varg, looptype, function ()
return ctx.frame:callParserFunction(magic, rargs)
return ctx.frame:expandTemplate(model)
end)
end)
return context_iterate(ctx, argc)
return context_iterate(ctx, argc)
Line 1,432: Line 1,491:




-- Syntax:  #invoke:params|renaming_by_replacing|target|replace|[count]|[plain
-- Syntax:  #invoke:params|renaming_by_invoking|module name|function
--            flag]|pipe to
--            name|[call style]|[let]|[...]|[number of additional
library.renaming_by_replacing = function (ctx)
--            arguments]|[argument 1]|[argument 2]|[...]|[argument N]|pipe to
local ptn, repl, nmax, is_strict, argc, die =
library.renaming_by_invoking = function (ctx)
load_replace_args(ctx.pipe, 'renaming_by_replacing')
local opts = ctx.pipe
if die then return context_iterate(ctx, argc) end
local mname
local tbl = ctx.params
local fname
if is_strict then
if opts[1] ~= nil then mname = opts[1]:match'^%s*(.*%S)' end
local key = tonumber(ptn) or ptn:match'^%s*(.-)%s*$'
if mname == nil then error(modulename ..
local val = tbl[key]
', ‘renaming_by_invoking’: No module name was provided', 0) end
tbl[key] = nil
if opts[2] ~= nil then fname = opts[2]:match'^%s*(.*%S)' end
tbl[tonumber(repl) or repl:match'^%s*(.-)%s*$'] = val
if fname == nil then error(modulename ..
else
', ‘renaming_by_invoking’: No function name was provided', 0) end
if flg == 2 then
local rargs, argc, looptype, karg, varg = load_callback_opts(opts, 2,
-- Copied from Module:String's `str._escapePattern()`
mapping_styles.names_only)
ptn = ptn:gsub('[%(%)%.%%%+%-%*%?%[%^%$%]]', '%%%0')
local model = { title = 'Module:' .. mname, args = rargs }
end
local mfunc = require(model.title)[fname]
local cache = {}
if mfunc == nil then error(modulename ..
for key, val in pairs(tbl) do
', ‘renaming_by_invoking’: The function ‘' .. fname ..
steal_if_renamed(val, tbl, key, cache,
'’ does not exist', 0) end
tostring(key):gsub(ptn, repl, nmax))
map_names(ctx.params, rargs, karg, varg, looptype, function ()
end
local tmp = mfunc(ctx.frame:newChild(model))
for key, val in pairs(cache) do tbl[key] = val end
return tonumber(tmp) or tostring(tmp)
end
end)
return context_iterate(ctx, argc)
return context_iterate(ctx, argc)
end
end




-- Syntax:  #invoke:params|grouping_by_calling|template
-- Syntax:  #invoke:params|renaming_by_magic|parser function|[call
--            name|[let]|[...]|[number of additional arguments]|[argument
--            style]|[let]|[...][number of additional arguments]|[argument
--            1]|[argument 2]|[...]|[argument N]|pipe to
--            1]|[argument 2]|[...]|[argument N]|pipe to
library.grouping_by_calling = function (ctx)
library.renaming_by_magic = function (ctx)
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- this function MUST create a copy of it before returning
local opts = ctx.pipe
local opts = ctx.pipe
local tmp
local magic
if opts[1] ~= nil then tmp = opts[1]:match'^%s*(.*%S)' end
if opts[1] ~= nil then magic = opts[1]:match'^%s*(.*%S)' end
if tmp == nil then error(modulename ..
if magic == nil then error(modulename ..
', ‘grouping_by_calling’: No template name was provided', 0) end
', ‘renaming_by_magic’: No parser function was provided', 0) end
local model = { title = tmp }
local rargs, argc, looptype, karg, varg = load_callback_opts(opts, 1,
local tmp, argc = load_child_opts(opts, 2, 0)
mapping_styles.names_only)
local gargs = {}
map_names(ctx.params, rargs, karg, varg, looptype, function ()
for key, val in pairs(tmp) do
return ctx.frame:callParserFunction(magic, rargs)
if type(key) == 'number' and key < 1 then gargs[key - 1] = val
end)
else gargs[key] = val end
return context_iterate(ctx, argc)
end
 
 
-- Syntax:  #invoke:params|renaming_by_replacing|target|replace|[count]|[plain
--            flag]|pipe to
library.renaming_by_replacing = function (ctx)
local ptn, repl, nmax, flg, argc, die =
load_replace_args(ctx.pipe, 'renaming_by_replacing')
if die then return context_iterate(ctx, argc) end
local tbl = ctx.params
if flg == 3 then
local key = tonumber(ptn) or ptn:match'^%s*(.-)%s*$'
local val = tbl[key]
if val ~= nil then
tbl[key] = nil
tbl[tonumber(repl) or repl:match'^%s*(.-)%s*$'] = val
end
else
if flg == 2 then
-- Copied from Module:String's `str._escapePattern()`
ptn = ptn:gsub('[%(%)%.%%%+%-%*%?%[%^%$%]]', '%%%0')
end
local cache = {}
for key, val in pairs(tbl) do
steal_if_renamed(val, tbl, key, cache,
tostring(key):gsub(ptn, repl, nmax))
end
for key, val in pairs(cache) do tbl[key] = val end
end
return context_iterate(ctx, argc)
end
 
 
-- Syntax:  #invoke:params|renaming_by_mixing|mixing string|pipe to
library.renaming_by_mixing = function (ctx)
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- this function MUST create a copy of it before returning
if ctx.pipe[1] == nil then error(modulename ..
', ‘renaming_by_mixing’: No mixing string was provided', 0) end
local mix = ctx.pipe[1]:match'^%s*(.-)%s*$'
local cache = {}
if mix == '$@' then
for _, val in pairs(ctx.params) do cache[val] = val end
else
local skel, canvas, n_parts = parse_placeholder_string(mix)
local tmp
for key, val in pairs(ctx.params) do
for idx = 2, n_parts, 2 do
if skel[idx] then canvas[idx] = val
else canvas[idx] = tostring(key) end
end
tmp = table.concat(canvas)
cache[tonumber(tmp) or tmp] = val
end
end
ctx.params = cache
return context_iterate(ctx, 2)
end
 
 
-- Syntax:  #invoke:params|renaming_to_values|pipe to
--[[
library.renaming_to_values = function (ctx)
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- this function MUST create a copy of it before returning
local cache = {}
for _, val in pairs(ctx.params) do cache[val] = val end
ctx.params = cache
return context_iterate(ctx, 1)
end
]]--
 
 
-- Syntax:  #invoke:params|grouping_by_calling|template
--            name|[let]|[...]|[number of additional arguments]|[argument
--            1]|[argument 2]|[...]|[argument N]|pipe to
library.grouping_by_calling = function (ctx)
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- this function MUST create a copy of it before returning
local opts = ctx.pipe
local tmp
if opts[1] ~= nil then tmp = opts[1]:match'^%s*(.*%S)' end
if tmp == nil then error(modulename ..
', ‘grouping_by_calling’: No template name was provided', 0) end
local model = { title = tmp }
local tmp, argc = load_child_opts(opts, 2, 0)
local gargs = {}
for key, val in pairs(tmp) do
if type(key) == 'number' and key < 1 then gargs[key - 1] = val
else gargs[key] = val end
end
local groups = make_groups(ctx.params)
for gid, group in pairs(groups) do
for key, val in pairs(gargs) do group[key] = val end
group[0] = gid
model.args = group
groups[gid] = ctx.frame:expandTemplate(model)
end
ctx.params = groups
return context_iterate(ctx, argc)
end
 
 
-- Syntax:  #invoke:params|parsing|string to parse|[trim flag]|[iteration
--            delimiter setter]|[...]|[key-value delimiter setter]|[...]|pipe to
library.parsing = function (ctx)
local opts = ctx.pipe
if opts[1] == nil then error(modulename ..
', ‘parsing’: No string to parse was provided', 0) end
local isep, iplain, psep, pplain, trimnamed, trimunnamed, argc =
load_parse_opts(opts, 2)
parse_parameter_string(ctx.params, opts[1], isep, iplain, psep, pplain,
trimnamed, trimunnamed)
return context_iterate(ctx, argc)
end
 
 
-- Syntax:  #invoke:params|reinterpreting|parameter to reinterpret|[trim
--            flag]|[iteration delimiter setter]|[...]|[key-value delimiter
--            setter]|[...]|pipe to
library.reinterpreting = function (ctx)
local opts = ctx.pipe
if opts[1] == nil then error(modulename ..
', ‘reinterpreting’: No parameter to reinterpret was provided', 0) end
local isep, iplain, psep, pplain, trimnamed, trimunnamed, argc =
load_parse_opts(opts, 2)
local tbl = ctx.params
local tmp = tonumber(opts[1]) or opts[1]:match'^%s*(.-)%s*$'
local str = tbl[tmp]
if str ~= nil then
tbl[tmp] = nil
parse_parameter_string(tbl, str, isep, iplain, psep, pplain,
trimnamed, trimunnamed)
end
return context_iterate(ctx, argc)
end
 
 
-- Syntax:  #invoke:params|mixing_names_and_values|mixing string|pipe to
library.mixing_names_and_values = function (ctx)
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
-- this function MUST create a copy of it before returning
if ctx.pipe[1] == nil then error(modulename ..
', ‘mixing_names_and_values’: No mixing string was provided for parameter names', 0) end
if ctx.pipe[2] == nil then error(modulename ..
', ‘mixing_names_and_values’: No mixing string was provided for parameter values', 0) end
local mix_k = ctx.pipe[1]:match'^%s*(.-)%s*$'
local mix_v = ctx.pipe[2]
local cache = {}
if mix_k == '$@' and mix_v == '$@' then
for _, val in pairs(ctx.params) do cache[val] = val end
elseif mix_k == '$@' and mix_v == '$#' then
for key, val in pairs(ctx.params) do cache[val] = key end
elseif mix_k == '$#' and mix_v == '$#' then
for _, val in pairs(ctx.params) do cache[key] = key end
else
local skel_k, cnv_k, n_parts_k = parse_placeholder_string(mix_k)
local skel_v, cnv_v, n_parts_v = parse_placeholder_string(mix_v)
local tmp
for key, val in pairs(ctx.params) do
tmp = tostring(key)
for idx = 2, n_parts_k, 2 do
if skel_k[idx] then cnv_k[idx] = val else cnv_k[idx] = tmp end
end
for idx = 2, n_parts_v, 2 do
if skel_v[idx] then cnv_v[idx] = val else cnv_v[idx] = tmp end
end
tmp = table.concat(cnv_k)
cache[tonumber(tmp) or tmp] = table.concat(cnv_v)
end
end
end
local groups = make_groups(ctx.params)
ctx.params = cache
for gid, group in pairs(groups) do
return context_iterate(ctx, 3)
for key, val in pairs(gargs) do group[key] = val end
group[0] = gid
model.args = group
groups[gid] = ctx.frame:expandTemplate(model)
end
ctx.params = groups
return context_iterate(ctx, argc)
end
end




-- Syntax:  #invoke:params|parsing|string to parse|[trim flag]|[iteration
-- Syntax:  #invoke:params|swapping_names_and_values|pipe to
--           delimiter setter]|[...]|[key-value delimiter setter]|[...]|pipe to
--[[
library.parsing = function (ctx)
library.swapping_names_and_values = function (ctx)
local opts = ctx.pipe
-- NOTE: `ctx.params` might be the original metatable! As a modifier,
if opts[1] == nil then error(modulename ..
-- this function MUST create a copy of it before returning
', ‘parsing’: No string to parse was provided', 0) end
local cache = {}
local isep, iplain, psep, pplain, trimnamed, trimunnamed, argc =
for key, val in pairs(ctx.params) do cache[val] = key end
load_parse_opts(opts, 2)
ctx.params = cache
parse_parameter_string(ctx.params, opts[1], isep, iplain, psep, pplain,
return context_iterate(ctx, 1)
trimnamed, trimunnamed)
return context_iterate(ctx, argc)
end
 
 
-- Syntax:  #invoke:params|reinterpreting|parameter to reinterpret|[trim
--            flag]|[iteration delimiter setter]|[...]|[key-value delimiter
--           setter]|[...]|pipe to
library.reinterpreting = function (ctx)
local opts = ctx.pipe
if opts[1] == nil then error(modulename ..
', ‘reinterpreting’: No parameter to reinterpret was provided', 0) end
local isep, iplain, psep, pplain, trimnamed, trimunnamed, argc =
load_parse_opts(opts, 2)
local tbl = ctx.params
local tmp = tonumber(opts[1]) or opts[1]:match'^%s*(.-)%s*$'
local str = tbl[tmp]
if str ~= nil then
tbl[tmp] = nil
parse_parameter_string(tbl, str, isep, iplain, psep, pplain,
trimnamed, trimunnamed)
end
return context_iterate(ctx, argc)
end
end
]]--




Line 1,711: Line 1,909:
'’ does not exist', 0) end
'’ does not exist', 0) end
ctx.text = mfunc(ctx.frame:newChild{
ctx.text = mfunc(ctx.frame:newChild{
title = 'Module:' .. fname,
title = 'Module:' .. mname,
args = concat_params(ctx)
args = concat_params(ctx)
})
})
Line 1,851: Line 2,049:
local ret = {}
local ret = {}
local nss = 0
local nss = 0
local skel, cnv, n_parts = parse_placeholder_string(txt)
flush_params(
flush_params(
ctx,
ctx,
function (key, val)
function (key, val)
for idx = 2, n_parts, 2 do
if skel[idx] then cnv[idx] = val
else cnv[idx] = tostring(key) end
end
ret[nss + 1] = pps
ret[nss + 1] = pps
ret[nss + 2] = txt:gsub('%$#', key):gsub('%$@', val)
ret[nss + 2] = table.concat(cnv)
nss = nss + 2
nss = nss + 2
end
end
Line 1,972: Line 2,175:
opts[2] = val
opts[2] = val
ret[nss + 1] = ccs
ret[nss + 1] = ccs
ret[nss + 2] = ctx.frame:callParserFunction(magic,
ret[nss + 2] = ctx.frame:callParserFunction(magic, opts)
opts)
nss = nss + 2
nss = nss + 2
end
end
Line 2,086: Line 2,288:
opts[1] = val
opts[1] = val
ret[nss + 1] = ccs
ret[nss + 1] = ccs
ret[nss + 2] = ctx.frame:callParserFunction(magic,
ret[nss + 2] = ctx.frame:callParserFunction(magic, opts)
opts)
nss = nss + 2
nss = nss + 2
end
end
Line 2,201: Line 2,402:
return function (frame)
return function (frame)
local ctx = context_new(frame:getParent())
local ctx = context_new(frame:getParent())
ctx.pipe = copy_or_ref_table(frame.args,
ctx.pipe = copy_or_ref_table(frame.args, refpipe[fname])
refpipe[fname])
ctx.params = copy_or_ref_table(ctx.oparams, refparams[fname])
ctx.params = copy_or_ref_table(ctx.oparams,
refparams[fname])
main_loop(ctx, func)
main_loop(ctx, func)
return ctx.text
return ctx.text