Module:pollasena-roots: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(78 intermediate revisions by the same user not shown)
Line 1: Line 1:
local m_iut = require("Module:inflection utilities")
local m_put = require("Module:parse utilities")
local m_table = require("Module:table")
local m_families = require("Module:families")


local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local match = mw.ustring.match
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gmatch = mw.ustring.gmatch
local lang = require("Module:languages").getByCode("socl")


local export = {}
local export = {}
Line 17: Line 16:
end
end


return table.concat(out_categories, "")
return NAMESPACE == "Template" and "" or table.concat(out_categories, "")
end
end


local function link(term,alt)
local function link(lang, term, alt)
return "[[Contionary:*" .. term .. "|*" .. (alt or term) .. "]]"
local natlang = lang:getWikidataItem() or false
-- true if the language declaration has a wikidata item, a marginal amount of conlangs have it
term = (lang:getType() == "reconstructed" and "*" or "") .. term
local data = {term = term, alt = alt, lang = lang, nocont = natlang}
return require('Module:links').full_link(data)
end
end


function export.getLink(frame)
function export.getLink(frame)
local a = 2
local params = {}
local params = {
local a = 0
[1] = {},
[a] = {list = true}, -- Wascotl
if frame.args["older"] then
}
params[1] = {}
params[2] = {list = true}
a = 2
else
params[1] = {list = true}
a = 1
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local param_mods = {"alt", "cat"}
local param_mod_set = m_table.listToSet(param_mods)
local fam, lang = m_families.getByCode(frame.args[1]), require("Module:languages").getByCode(frame.args[2])
local links = {}; local categories = {}
local proto = fam:getProtoLanguage()
 
local links = {}; local categories = {}; local alts = {};
-- WIP
-- WIP
for i, item in ipairs(args[a]) do
for i, item in ipairs(args[a]) do
if item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then
if item == "+" then
local run = m_iut.parse_balanced_segment_run(item, "<", ">")
table.insert(links,"&nbsp;")
local orig_param = i + 1
elseif item == "-" then
table.insert(links, item)
elseif item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then
local run = m_put.parse_balanced_segment_run(item, "<", ">")
local orig_param = a + i - 1
local function parse_err(msg)
local function parse_err(msg)
error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
end
end
local termobj = {term = {}}
local term = run[1]:gsub("%*","")
termobj.term.lang = lang
termobj.term.term = run[1]


for j = 2, #run - 1, 2 do
for j = 2, #run - 1, 2 do
if run[j + 1] ~= "" then
parse_err("Extraneous text '" .. run[j + 1] .. "' after modifier")
end
local modtext = run[j]:match("^<(.*)>$")
local modtext = run[j]:match("^<(.*)>$")
if not modtext then
parse_err("Internal error: Modifier '" .. modtext .. "' isn't surrounded by angle brackets")
end
local prefix, arg = modtext:match("^([a-z]+):(.*)$")
local prefix, arg = modtext:match("^([a-z]+):(.*)$")
if not prefix then
parse_err("Modifier " .. run[j] .. " lacks a prefix, should begin with one of '" ..
if item:match("><") then
table.concat(param_mods, ":', '") .. ":'")
if prefix == "a" then
end
table.insert(links, link(proto, term, arg))
if param_mod_set[prefix] then
table.insert(alts, arg)
local obj = termobj.term
elseif prefix == "c" then
if obj[prefix] then
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
parse_err("Modifier '" .. prefix .. "' occurs twice, second occurrence " .. run[j])
table.insert(alts, term)
end
end
elseif prefix == "a" then
table.insert(links, link(obj.term, obj["alt"]))
table.insert(links, link(proto, term, arg))
table.insert(categories, "Soc'ul' terms inherited from Wascotl *" .. (obj["cat"] or obj.term))
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. term)
else
table.insert(alts, arg)
parse_err("Unrecognized prefix '" .. prefix .. "' in modifier " .. run[j])
elseif prefix == "c" then
table.insert(links, link(proto, term))
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
table.insert(alts, term)
end
end
end
end
args[a][i] = termobj
else
table.insert(links, link(proto, args[a][i]))
table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. args[a][i])
table.insert(alts, args[a][i])
end
end
if i~=1 and links[i-1] == "-" then links[i] = links[i]:gsub("%|%*","|") end
if i~=1 and links[i-1] ~= "&nbsp;" then links[i] = links[i]:gsub("%|%*%-","|-") end
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
end
end