Module:pollasena-roots: Difference between revisions

No edit summary
No edit summary
 
(15 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, dest_code, ancestor_codes)
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
 
local function parse_args(parent_args, dest_code, ancestor_codes, extra_params)
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 = m_lang.getByCode(dest_code)
local params = extra_params or {}
local ancestor_lang, etymology
params.nocap = {type = "boolean"}
params.nocat = {type = "boolean"}
local ancestor_params, terms, args, etymologies = {}, {}, {}, {}
local termarg_index = 1
for ancestor_code, lang_options in pairs(ancestor_codes) do
for _, ancestor in ipairs(ancestor_codes) do
ancestor_params = {
local lang_options = ancestor.options or {}
["nocat"] = {type = "boolean"},
["nocap"] = {type = "boolean"},
[1] = {
required = not lang_options.optional,
list = lang_options.roots,
},
}
if lang_options.roots then
if lang_options.roots then
params[1].allow_holes = true
params[termarg_index] = {
required = not lang_options.optional,
list = true,
allow_holes = true,
}
else
params[termarg_index] = {
required = not lang_options.optional,
}
end
end
ancestor_lang = m_lang.getByCode(ancestor_code)
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 = {}
termarg_index = 1
for _, ancestor in ipairs(ancestor_codes) do
local code = ancestor.code
local lang_options = ancestor.options or {}
local ancestor_lang = m_lang.getByCode(code)
terms, arg = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
local terms
params = ancestor_params,
local separator = ""
param_mods = param_mods,
 
raw_args = parent_args,
if lang_options.roots then
termarg = 1,
local items = m_param_utils.parse_list_with_inline_modifiers_and_separate_params({
lang = ancestor_lang,
processed_args = args,
})
param_mods = param_mods,
termarg = termarg_index,
if not terms.terms[1] then
lang = ancestor_lang,
terms.terms[1] = {
})
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,
lang = ancestor_lang,
}
})
 
terms = parsed.terms or {}
if not terms[1] then
if parsed.term then
terms[1] = parsed
else
terms[1] = { lang = ancestor_lang }
end
end
end
end
 
terms = terms.terms
local etymology = m_etym.format_derived({
etymology = m_etym.format_derived({
lang = dest_lang,
lang = dest_lang,
sources = ancestor_lang,
sources = { ancestor_lang },
terms = terms[ancestor_code],
terms = terms,
conj = lang_options.roots and separator or nil,
nocat = args.nocat,
nocat = args.nocat,
template_name = "derived",
template_name = "derived",
})
})
 
table.insert(etymologies, etymology)
table.insert(etymologies, etymology)
termarg_index = termarg_index + 1
end
end
 
return etymologies
return etymologies, args
end
end


local function concat_etymologies(parent_args, etymologies)
local function concat_etymologies(args, etymologies)
 
local capital = args.nocap and "f" or "F"
local capital = parent_args.nocap and "f" or "F"
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
end
end
Line 172: Line 240:
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_codes = {
["sekh"] = {},
{ code = "sekh" },
["wasc"] = {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(parent_args, evolution)
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 = {
["lyti-mid"] = {optional = not parent_args.mid},
{ code = "lyti-mid", options = {optional = not parent_args.mid} },
["lyti-old"] = {optional = not parent_args.old},
{ code = "lyti-old", options = {optional = not parent_args.old} },
[source_code] = {},
{ code = source_code, options = {} },
}
}
local terms, args = 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(args, evolution)
end
end


return export
return export