Module:pollasena-roots: Difference between revisions
No edit summary |
No edit summary |
||
| (6 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 109: | 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 127: | Line 145: | ||
list = true, | list = true, | ||
allow_holes = true, | allow_holes = true, | ||
} | } | ||
else | else | ||
params[termarg_index] = { | params[termarg_index] = { | ||
required = not lang_options.optional, | required = not lang_options.optional, | ||
} | } | ||
end | end | ||
| Line 151: | Line 167: | ||
local lang_options = ancestor.options or {} | local lang_options = ancestor.options or {} | ||
local ancestor_lang = m_lang.getByCode(code) | local ancestor_lang = m_lang.getByCode(code) | ||
local terms | local terms | ||
local separator = "" | |||
if lang_options.roots then | if lang_options.roots then | ||
| Line 160: | Line 178: | ||
lang = ancestor_lang, | lang = ancestor_lang, | ||
}) | }) | ||
terms = items | |||
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 | else | ||
local single_args = get_single_args(args, termarg_index) | |||
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 = | processed_args = single_args, | ||
param_mods = param_mods, | param_mods = param_mods, | ||
termarg = termarg_index, | termarg = termarg_index, | ||
| Line 170: | Line 208: | ||
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 | ||
| Line 184: | Line 221: | ||
sources = { ancestor_lang }, | sources = { ancestor_lang }, | ||
terms = terms, | terms = terms, | ||
conj = lang_options.roots and separator or nil, | |||
nocat = args.nocat, | nocat = args.nocat, | ||
template_name = "derived", | template_name = "derived", | ||
| Line 204: | 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 } } | ||
} | } | ||