Module:bar-headword

local export = {} local pos_functions = {}

local list_to_set = require("Module:table").listToSet

local lang = require("Module:languages").getByCode("bar") local script = require('Module:scripts').getByCode("Latn")

-- If Not Empty local function ine(arg) if arg == "" then return nil else return arg end end

local function append_cat(data, pos) table.insert(data.categories, lang:getCanonicalName .. " " .. pos) end

local function handle_infl(args, data, argpref, label) if args[argpref] and args[argpref..'2'] then local forms = {} local form = argpref local i = 1 while args[form] do			table.insert (forms, args[form]) i = i + 1 form = argpref..i		end forms.label = mw.ustring.gsub(label, 'form', 'forms') table.insert(data.inflections, forms ) elseif args[argpref] then table.insert(data.inflections, { label = label, args[argpref]}) end end

function export.show(frame)

local args = frame:getParent.args local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") poscat = string.gsub(poscat, 'form', 'forms') local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = {args["head"] or PAGENAME}, genders = {}, inflections = {}, sort_key = args["sort"]} if poscat == 'nouns' then if ine(args[1]) then args['g'] = args[1] end if ine(args[2]) then args['pl'] = args[2] end if ine(args[3]) then args['gen'] = args[3] end end if args["cat2"] then table.insert(data.categories, "Bavarian " .. args["cat2"]) end if args["cat3"] then table.insert(data.categories, "Bavarian " .. args["cat3"]) end handle_infl(args, data, "stem", "stem") if pos_functions[poscat] then pos_functions[poscat](args, data) end return require("Module:headword").full_headword(data) end

local valid_genders = list_to_set(		{ "m", "m-p",		 "f", "f-p",		  "n", "n-p"		})

local function handle_gender(args, data, default, nonlemma, optional)

local g = ine(args["g"]) or default local g2 = ine(args["g2"])

local function process_gender(gender) if not gender and not optional then table.insert(data.genders, "?") elseif not gender and optional then -- do nothing elseif valid_genders[g] then table.insert(data.genders, gender) else error("Unrecognized gender: " .. gender) end end

process_gender(g) if g2 then process_gender(g2) end

if nonlemma then return end

if g and g2 then append_cat(data, "terms with multiple genders") end end

local function is_masc_sg(g) return g == "m" or g == "m-p" end local function is_fem_sg(g) return g == "f" or g == "f-p" end local function is_neut_sg(g) return g == "n" or g == "n-p" end

pos_functions["adjectives"] = function(args, data) handle_infl(args, data, "cp", "comperative") handle_infl(args, data, "sup", "superlative") end

pos_functions["articles"] = function(args, data) handle_gender(args, data) handle_infl(args, data, "acc", "accusative") handle_infl(args, data, "dat", "dative") end

pos_functions["nouns"] = function(args, data) handle_gender(args, data) handle_infl(args, data, "gen", "genitive") handle_infl(args, data, "pl", "plural") handle_infl(args, data, "f", "feminine") local g = ine(args["g"]) or default local g2 = ine(args["g2"])

if is_masc_sg(g) or is_masc_sg(g2) then append_cat(data, "masculine nouns") elseif is_fem_sg(g) or is_fem_sg(g2) then append_cat(data, "feminine nouns") elseif is_neut_sg(g) or is_neut_sg(g2) then append_cat(data, "neuter nouns") end end

pos_functions["pronouns"] = function(args, data) handle_infl(args, data, "pl", "plural") end

pos_functions["verbs"] = function(args, data) handle_infl(args, data, "pp", "past participle") handle_infl(args, data, "past", "3rd person singular past") if ine(args['past']) then handle_infl(args, data, "subj", "subjunctive") else handle_infl(args, data, "subj", "3rd person singular subjunctive") end end

return export