Module:pollasena-roots: Difference between revisions
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 113: | Line 113: | ||
return table.concat(links) .. ncategories(categories) | return table.concat(links) .. ncategories(categories) | ||
end | |||
local function get_single_args(args, index) | |||
local single = {} | |||
for k, v in pairs(args) do | |||
if type(v) == "table" and v.maxindex then | |||
if v[index] ~= nil then | |||
single[k] = v[index] | |||
end | |||
else | |||
single[k] = v | |||
end | |||
end | |||
return single | |||
end | end | ||
| Line 118: | Line 132: | ||
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}}) | local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}}) | ||
local dest_lang = | local params = extra_params or {} | ||
params.nocap = {type = "boolean"} | |||
params.nocat = {type = "boolean"} | |||
local termarg_index = 1 | |||
for _, ancestor in ipairs(ancestor_codes) do | |||
local lang_options = ancestor.options or {} | |||
if lang_options.roots then | |||
params[termarg_index] = { | |||
required = not lang_options.optional, | |||
list = true, | |||
allow_holes = true, | |||
} | |||
else | |||
params[termarg_index] = { | |||
required = not lang_options.optional, | |||
} | |||
end | |||
termarg_index = termarg_index + 1 | |||
end | |||
m_param_utils.augment_params_with_modifiers(params, param_mods) | |||
local args = m_param.process(parent_args, params) | |||
local dest_lang = m_lang.getByCode(dest_code) | |||
local etymologies = {} | local etymologies = {} | ||
termarg_index = 1 | |||
for _, ancestor in ipairs(ancestor_codes) do | for _, ancestor in ipairs(ancestor_codes) do | ||
local code = ancestor.code | local code = ancestor.code | ||
local lang_options = ancestor.options or {} | local lang_options = ancestor.options or {} | ||
local ancestor_lang = | local ancestor_lang = m_lang.getByCode(code) | ||
local terms | local terms | ||
local separator = "" | |||
if lang_options.roots then | if lang_options.roots then | ||
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({ | local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({ | ||
processed_args = args, | |||
param_mods = param_mods, | param_mods = param_mods, | ||
termarg = termarg_index, | termarg = termarg_index, | ||
| Line 149: | Line 179: | ||
}) | }) | ||
terms = {} | terms = {} | ||
local root_index = 1 | |||
for _, item in ipairs(items) do | for _, item in ipairs(items) do | ||
if item.term | if item.term == "-" or item.term == "+" then | ||
separator = item.term | |||
elseif item.term then | |||
if root_index > 1 and separator == "-" then -- no asterisk after hyphen | |||
if not item.alt then | |||
item.alt = item.term:gsub("^%*", "") | |||
else | |||
item.alt = item.alt:gsub("^%*", "") | |||
end | |||
item.no_alt_ast = true | |||
end | |||
table.insert(terms, item) | table.insert(terms, item) | ||
root_index = root_index + 1 | |||
end | end | ||
end | end | ||
else | else | ||
local single_args = get_single_args(args, termarg_index) | |||
local | |||
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({ | local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({ | ||
processed_args = single_args, | |||
param_mods = param_mods, | param_mods = param_mods, | ||
termarg = termarg_index, | termarg = termarg_index, | ||
| Line 187: | Line 221: | ||
sources = { ancestor_lang }, | sources = { ancestor_lang }, | ||
terms = terms, | terms = terms, | ||
conj = lang_options.roots and | conj = lang_options.roots and separator or nil, | ||
nocat = | nocat = args.nocat, | ||
template_name = "derived", | template_name = "derived", | ||
}) | }) | ||
| Line 196: | Line 230: | ||
end | end | ||
return etymologies | return etymologies, args | ||
end | end | ||
local function concat_etymologies( | local function concat_etymologies(args, etymologies) | ||
local capital = | local capital = args.nocap and "f" or "F" | ||
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "." | return capital .. "rom " .. table.concat(etymologies, ", from ") .. "." | ||
end | end | ||
| Line 208: | Line 242: | ||
local ancestor_codes = { | local ancestor_codes = { | ||
{ code = "sekh | { code = "sekh" }, | ||
{ code = "wasc", options = {optional = true, roots = true | { code = "wasc", options = {optional = true, roots = true } } | ||
} | } | ||
local evolution = parse_args(parent_args, "qsc", ancestor_codes) | local evolution, args = parse_args(parent_args, "qsc", ancestor_codes) | ||
return concat_etymologies( | return concat_etymologies(args, evolution) | ||
end | end | ||
| Line 227: | Line 261: | ||
} | } | ||
local evolution = parse_args(parent_args, "lyti", ancestor_codes) | local extra_params = { | ||
mid = {type = "boolean"}, | |||
old = {type = "boolean"}, | |||
source = {}, | |||
} | |||
local evolution, args = parse_args(parent_args, "lyti", ancestor_codes, extra_params) | |||
return concat_etymologies( | return concat_etymologies(args, evolution) | ||
end | end | ||
return export | return export | ||