Module:pollasena-roots: Difference between revisions

No edit summary
No edit summary
Line 145: Line 145:
list = true,
list = true,
allow_holes = true,
allow_holes = true,
default = lang_options.default,
}
}
else
else
params[termarg_index] = {
params[termarg_index] = {
required = not lang_options.optional,
required = not lang_options.optional,
default = lang_options.default,
}
}
end
end
Line 159: Line 161:
local args = m_param.process(parent_args, params)
local args = m_param.process(parent_args, params)


local dest_lang = m_lang.getByCode(dest_code)
local dest_lang = lang_from_code(dest_code)
local etymologies = {}
local etymologies = {}
Line 166: Line 168:
local code = ancestor.code
local code = ancestor.code
local lang_options = ancestor.options or {}
local lang_options = ancestor.options or {}
local ancestor_lang = m_lang.getByCode(code)
local ancestor_lang = lang_from_code(code)
local terms
local raw_val = parent_args[termarg_index] or parent_args[tostring(termarg_index)]
local separator = ""
if lang_options.optional and (raw_val == nil or raw_val == "") then
termarg_index = termarg_index + 1
else
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,
processed_args = args,
param_mods = param_mods,
param_mods = param_mods,
termarg = termarg_index,
termarg = termarg_index,
lang = ancestor_lang,
lang = ancestor_lang,
})
})
terms = {}
terms = {}
local root_index = 1
local root_index = 1
for _, item in ipairs(items) do
for _, item in ipairs(items) do
if item.term == "-" or item.term == "+" then
if item.term == "-" or item.term == "+" then
separator = item.term
separator = item.term
elseif item.term then
elseif item.term then
if root_index > 1 and separator == "-" then -- no asterisk after hyphen
if root_index > 1 and separator == "-" then -- no asterisk after hyphen
if not item.alt then
if not item.alt then
item.alt = item.term:gsub("^%*", "")
item.alt = item.term:gsub("^%*", "")
else
else
item.alt = item.alt:gsub("^%*", "")
item.alt = item.alt:gsub("^%*", "")
end
item.no_alt_ast = true
end
end
item.no_alt_ast = true
table.insert(terms, item)
root_index = root_index + 1
end
end
table.insert(terms, item)
root_index = root_index + 1
end
end
end
else
if not terms[1] then
local single_args = get_single_args(args, termarg_index)
terms[1] = { lang = ancestor_lang }
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
end
processed_args = single_args,
else
param_mods = param_mods,
local single_args = get_single_args(args, termarg_index)
termarg = termarg_index,
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
lang = ancestor_lang,
processed_args = single_args,
})
param_mods = param_mods,
termarg = termarg_index,
lang = ancestor_lang,
})


terms = parsed.terms or {}
terms = parsed.terms or {}
if not terms[1] then
if not terms[1] then
if parsed.term then
if parsed.term then
terms[1] = parsed
terms[1] = parsed
else
else
terms[1] = { lang = ancestor_lang }
terms[1] = { lang = ancestor_lang }
end
end
end
end
end
end


local etymology = m_etym.format_derived({
local etymology = m_etym.format_derived({
lang = dest_lang,
lang = dest_lang,
sources = { ancestor_lang },
sources = { ancestor_lang },
terms = terms,
terms = terms,
conj = lang_options.roots and separator or nil,
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
termarg_index = termarg_index + 1
end
end
end