Module:descendants: Difference between revisions

Jump to navigation Jump to search
m
Optimisation
m (Optimisation)
m (Optimisation)
Line 129: Line 129:
for i, term in ipairs(args) do --ryn:term1|term2|term3|rad:term1|term2 ...
for i, term in ipairs(args) do --ryn:term1|term2|term3|rad:term1|term2 ...
local lang_change = mw.ustring.match(term, "^([^%:%<]+)%:")
local lang_change = mw.ustring.match(term, "^([^%:%<]+)%:") or mw.ustring.match(term, "^(.+%>)%:")
local lang_change_arged = mw.ustring.match(term, "^(.+%>)%:")
if i == 1 and lang_change == nil then error("No language code in the first parameter") end
local from_lang, index
if lang_change then
if i == 1 and not (lang_change or lang_change_arged) then error("Language code needs to be specified in the first parameter as xyz(<bor>):term₁") end
term = mw.ustring.sub(term, mw.ustring.len(lang_change) + 2)
if lang_change or lang_change_arged then
if lang_change then
local lang_args = {}
current_lang = lang_change
code, lang_args = m_inline.parse(lang_change)
term = mw.ustring.gsub(term, "^[^%:]+%:%s*", "")
-- if new language, build table
elseif lang_change_arged then
current_lang = mw.ustring.match(lang_change_arged, "^[^%<]+")
term = mw.ustring.gsub(term, "^.+%>%:%s*", "")
end
if mw.ustring.find(current_lang, "[%>%_][^%:]") then
from_lang, current_lang = mw.ustring.match(current_lang, "^(.*[%>%_])([^%>%_%:]+)$")
if mw.ustring.match(from_lang, "%>$") then
if lang_change_arged then
lang_change_arged = lang_change_arged .. "<bor>"
else
lang_change_arged = "<bor>"
end
end
end
if mw.ustring.find(current_lang, "[0-9]+$") then
current_lang, index = mw.ustring.match(current_lang, "^(.*)([0-9]+)$")
end
current_lang = m_languages.get_by_code(current_lang)
code = current_lang.code
if from_lang then code = from_lang .. code end
if index then code = code .. index end
if terms[code] == nil then
if terms[code] == nil then
terms[code] = {}
terms[code] = {}
table.insert(langs, code)
table.insert(langs, code)
end
current_lang = code
local delim
lang_args["from"], delim, current_lang = mw.ustring.match(current_lang, "^(.*)([%>%_])([^%>%_%:0-9]+)[0-9]*$")
if delim and delim == ">" then lang_args["bor"] = true end
-- process arguments
for lang_arg, lang_val in pairs(lang_args) do
    terms[code][lang_arg] = lang_val
end
end
end
end
if lang_change_arged then
for lang_arg in mw.ustring.gmatch(lang_change_arged, "<([^>]+)>") do
    local s = mw.text.split(lang_arg, ":", true)
    terms[code][s[1]] = s[2] or true
    if #s > 2 then mw.addWarning("multiple : found in inline string") end
    end
end
if from_lang then terms[code]["from"] = from_lang end
table.insert(terms[code], term)
table.insert(terms[code], term)
end
end
Line 237: Line 218:
Debug console test string:
Debug console test string:
=p.descendant(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}})
=p.descendant(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}})
=p.desctree(mw.getCurrentFrame():newChild{title="whatever",args={"ryn>rad-o:1", "aeg:2", "3", "ryn:4", "ryn>rad-o_rad:5", ">rad-pro:6", "hrd-pro:7", "ryn-o:8", "lfv-pro:9", "lfv-o:10", "lfv:11", "rad-pro:12"}})
=p.desctree(mw.getCurrentFrame():newChild{title="whatever",args={"ryn>rad-o:1", "aeg:2", "3", "ryn:4", "ryn>rad-o_rad:5", ">rad-pro:6", "hrd-pro:7", "ryn-o:8", "lfv-pro:9", "lfv-o:10", "lfv:11", "rad-pro:12", "kil<lost:oh no>:", "bal<bor>:13"}})
]]--
]]--

Navigation menu