45,647
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local m_iut = require("Module:inflection utilities") | |||
local m_table = require("Module:table") | |||
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", " ") | ||
Line 8: | Line 11: | ||
local export = {} | local export = {} | ||
local function link(term) | local function link(term,alt) | ||
return "[[Contionary:" .. term .. "|" .. term .. "]]" | return "[[Contionary:" .. term .. "|" .. alt or term .. "]]" | ||
end | end | ||
function export.getLink(frame) | function export.getLink(frame) | ||
local a = 1 | |||
local params = { | |||
[a] = {list = true}, -- Wascotl | |||
} | |||
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 categories = {} | local categories = {} | ||
-- WIP | -- WIP | ||
for i, item in ipairs(args[a]) do | |||
if item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then | |||
local run = m_iut.parse_balanced_segment_run(item, "<", ">") | |||
local orig_param = i | |||
local function parse_err(msg) | |||
error(msg .. ": " .. orig_param .. "= " .. table.concat(run)) | |||
end | |||
local termobj = {term = {}} | |||
termobj.term.lang = lang | |||
termobj.term.term = run[1] | |||
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("^<(.*)>$") | |||
if not modtext then | |||
parse_err("Internal error: Modifier '" .. modtext .. "' isn't surrounded by angle brackets") | |||
end | |||
local prefix, arg = modtext:match("^([a-z]+):(.*)$") | |||
if not prefix then | |||
parse_err("Modifier " .. run[j] .. " lacks a prefix, should begin with one of '" .. | |||
table.concat(param_mods, ":', '") .. ":'") | |||
end | |||
if param_mod_set[prefix] then | |||
local obj = termobj.term | |||
if obj[prefix] then | |||
parse_err("Modifier '" .. prefix .. "' occurs twice, second occurrence " .. run[j]) | |||
end | |||
table.insert(links, link(obj.term, obj["alt"])) | |||
table.insert(categories, "Soc'ul' terms derived from Wascotl *" .. obj["cat"] or obj.term) | |||
else | |||
parse_err("Unrecognized prefix '" .. prefix .. "' in modifier " .. run[j]) | |||
end | |||
end | |||
args[a][i] = termobj | |||
end | |||
end | |||
return ncategories(categories) | return table.concat(links) .. ncategories(categories) | ||
end | end | ||
return export | return export |