Module:pollasena-roots: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 14: Line 14:


local export = {}
local export = {}
local function lang_from_code(...)
return m_lang.getByCode(...)
end


local function ncategories(categories)
local function ncategories(categories)
Line 111: Line 115:
end
end


local function parse_args(parent_args, ancestor_specs)
local function get_single_args(args, index)
local param_mods = m_param_utils.construct_param_mods({
local single = {}
{ group = {"link", "q", "l"} },
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


local parsed = {}
local function parse_args(parent_args, dest_code, ancestor_codes, extra_params)
local common = {
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}})
nocat = parent_args.nocat,
nocap = parent_args.nocap,
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)


for i, spec in ipairs(ancestor_specs) do
local dest_lang = m_lang.getByCode(dest_code)
local lang = m_lang.getByCode(spec.code)
local etymologies = {}
local params = {
[1] = {
termarg_index = 1
required = not spec.optional,
for _, ancestor in ipairs(ancestor_codes) do
list = spec.roots and "term",
local code = ancestor.code
allow_holes = spec.roots or nil,
local lang_options = ancestor.options or {}
},
local ancestor_lang = m_lang.getByCode(code)
}
local terms
local separator = ""


local terms_obj = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
if lang_options.roots then
params = params,
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({
param_mods = param_mods,
processed_args = args,
raw_args = { [1] = parent_args[i] }, -- map positional arg i -> local [1]
param_mods = param_mods,
termarg = 1,
termarg = termarg_index,
lang = lang,
lang = ancestor_lang,
sc = "sc.default",
})
})
terms = {}
local root_index = 1
for _, item in ipairs(items) do
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)
root_index = root_index + 1
end
end
else
local single_args = get_single_args(args, termarg_index)
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
processed_args = single_args,
param_mods = param_mods,
termarg = termarg_index,
lang = ancestor_lang,
})


local terms = terms_obj.terms
terms = parsed.terms or {}
if not terms[1] then
if not terms[1] then
terms[1] = { lang = lang } -- allow empty optional term if desired
if parsed.term then
terms[1] = parsed
else
terms[1] = { lang = ancestor_lang }
end
end
end
end


parsed[i] = {
local etymology = m_etym.format_derived({
lang = lang,
lang = dest_lang,
sources = { ancestor_lang },
terms = terms,
terms = terms,
}
conj = lang_options.roots and separator or nil,
nocat = args.nocat,
template_name = "derived",
})
 
table.insert(etymologies, etymology)
termarg_index = termarg_index + 1
end
end


return parsed, common
return etymologies, args
end
end


local function concat_etymologies(parsed, opts, dest_lang)
local function concat_etymologies(args, etymologies)
local chunks = {}
local capital = args.nocap and "f" or "F"
 
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
for _, item in ipairs(parsed) do
if item.terms and item.terms[1] then
table.insert(chunks, m_etym.format_derived({
lang = dest_lang,
sources = { item.lang },
terms = item.terms,
nocat = opts.nocat,
template_name = "der",
}))
end
end
local capital = opts.nocap and "f" or "F"
local text = capital .. "rom " .. table.concat(chunks, ", from ")
return text .. "."
end
end


function export.qsc(frame)
function export.qsc(frame)
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local dest_lang = m_lang.getByCode("qsc")
 
local ancestor_codes = {
local ancestor_specs = {
{ code = "sekh" },
{ code = "sekh", optional = false },
{ code = "wasc", options = {optional = true, roots = true } }
{ code = "wasc", optional = true, roots = true },
}
}
 
local parsed, opts = parse_args(parent_args, ancestor_specs)
local evolution, args = parse_args(parent_args, "qsc", ancestor_codes)
return concat_etymologies(parsed, opts, dest_lang)
return concat_etymologies(args, evolution)
end
end


function export.lyti(frame)
function export.lyti(frame)
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local source_code = parent_args.source
local source_code = parent_args.source or "und"
 
local ancestor_codes = {
local ancestor_codes = {
{code = "lyti-mid", options = {optional = not parent_args.mid}},
{ code = "lyti-mid", options = {optional = not parent_args.mid} },
{code = "lyti-old", options = {optional = not parent_args.old}},
{ code = "lyti-old", options = {optional = not parent_args.old} },
{code = source_code, options = {}},
{ code = source_code, options = {} },
}
}
 
local etymologies = parse_args(parent_args, "lyti", ancestor_codes)
local extra_params = {
return concat_etymologies(parent_args, etymologies)
mid = {type = "boolean"},
old = {type = "boolean"},
source = {},
}
local evolution, args = parse_args(parent_args, "lyti", ancestor_codes, extra_params)
return concat_etymologies(args, evolution)
end
end


return export
return export