Documentation for this module may be created at မဝ်ဂျူ:pt-headword/doc

local export = {}
local pos_functions = {}
local rfind = mw.ustring.find
local rmatch = mw.ustring.match
local rsplit = mw.text.split

local m_links = require("Module:links")
local m_table = require("Module:table")
local com = require("Module:pt-common")
local romut_module = "Module:romance utilities"
local lang = require("Module:languages").getByCode("pt")
local langname = lang:getCanonicalName()

local suffix_categories = {
	["နာမဝိသေသန"] = true,
	["ကြိယာဝိသေသန"] = true,
	["နာမ်"] = true,
	["ကြိယာ"] = true,
	["prepositional phrases"] = true,
}

local function track(page)
	require("Module:debug/track")("pt-headword/" .. page)
	return true
end

local function glossary_link(entry, text)
	text = text or entry
	return "[[Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
end

local metaphonic_label = "[[:en:Appendix:Portuguese pronunciation#Metaphony|မေတာဖှဳနေတ်]]"

local function check_all_missing(forms, plpos, tracking_categories)
	for _, form in ipairs(forms) do
		if type(form) == "table" then
			form = form.term
		end
		if form then
			local title = mw.title.new(form)
			if title and not title.exists then
				
			end
		end
	end
end


-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

	local parargs = frame:getParent().args

	local params = {
		["head"] = {list = true},
		["splithyph"] = {type = "boolean"},
		["nolinkhead"] = {type = "boolean"},
		["json"] = {type = "boolean"},
		["pagename"] = {}, -- for testing
	}

	if pos_functions[poscat] then
		for key, val in pairs(pos_functions[poscat].params) do
			params[key] = val
		end
	end

	local args = require("Module:parameters").process(parargs, params)

	local pagename = args.pagename or mw.title.getCurrentTitle().text

	local heads = args["head"]
	if args.nolinkhead then
		if #heads == 0 then
			heads = {pagename}
		end
	else
		local auto_linked_head = require(romut_module).add_lemma_links(pagename, args.splithyph)
		if #heads == 0 then
			heads = {auto_linked_head}
		else
			for _, head in ipairs(heads) do
				if head == auto_linked_head then
					track("redundant-head")
				end
			end
		end
	end

	local data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = heads,
		genders = {},
		inflections = {},
		categories = {},
		pagename = pagename
	}

	if pagename:find("^%-") and suffix_categories[poscat] then
		data.pos_category = "suffixes"
		local singular_poscat = poscat:gsub("s$", "")
		table.insert(data.categories, langname .. " " .. singular_poscat .. "-forming suffixes")
	end

	local tracking_categories = {}

	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data, tracking_categories, frame)
	end

	if args["json"] then
		return require("Module:JSON").toJSON(data)
	end

	return require("Module:headword").full_headword(data)
		.. (#tracking_categories > 0 and require("Module:utilities").format_categories(tracking_categories, lang) or "")
end


local function fetch_qualifiers(qual, existing)
	if not qual then
		return existing
	end
	if not existing then
		return {qual}
	end
	local retval = {}
	for _, e in ipairs(existing) do
		table.insert(retval, e)
	end
	table.insert(retval, qual)
	return retval
end


local function process_terms_with_qualifiers(terms, quals)
	local infls = {}
	for i, term in ipairs(terms) do
		table.insert(infls, {term = term, qualifiers = fetch_qualifiers(quals[i])})
	end
	return infls
end


local function replace_hash_with_lemma(term, lemma)
	-- If there is a % sign in the lemma, we have to replace it with %% so it doesn't get interpreted as a capture replace
	-- expression.
	lemma = lemma:gsub("%%", "%%%%")
	-- Assign to a variable to discard second return value.
	term = term:gsub("#", lemma)
	return term
end

local function is_metaphonic(args, lemma)
	if args.nometa then
		return false
	end
	if args.meta then
		return true
	end
	-- Anything in -oso with a preceding vowel (e.g. [[gostoso]], [[curioso]]) is normally metaphonic.
	return rfind(lemma, com.V .. ".*oso$")
end

local allowed_genders = m_table.listToSet(
	{"m", "f", "mf", "mfbysense", "m-p", "f-p", "mf-p", "mfbysense-p", "?", "?-p", "n", "n-p"}
)

local function do_noun(args, data, tracking_categories, pos)
	local is_plurale_tantum = false
	local has_singular = false
	local plpos = require("Module:string utilities").pluralize(pos)

	data.genders = {}
	local saw_m = false
	local saw_f = false
	local gender_for_default_plural = args[1][1]
	for i, g in ipairs(args[1]) do
		if not allowed_genders[g] then
			error("Unrecognized gender: " .. g)
		end
		if g:find("-p$") then
			is_plurale_tantum = true
		else
			has_singular = true
			if g == "m" or g == "mf" or g == "mfbysense" then
				saw_m = true
			end
			if g == "f" or g == "mf" or g == "mfbysense" then
				saw_f = true
			end
		end
		if args.g_qual[i] then
			table.insert(data.genders, {spec = g, qualifiers = {args.g_qual[i]}})
		else
			table.insert(data.genders, g)
		end
	end
	if saw_m and saw_f then
		gender_for_default_plural = "mf"
	end

	local lemma = m_links.remove_links(data.heads[1]) -- should always be specified

	local function insert_inflection(list, term, accel, qualifiers, no_inv)
		local infl = {qualifiers = qualifiers, accel = accel}
		--if term == lemma and not no_inv then
		--	infl.label = glossary_link("invariable")
		--else
			infl.term = term
		--end
		infl.term_for_further_inflection = term
		table.insert(list, infl)
	end

	-- Plural
	local plurals = {}
	local args_mpl = args.mpl
	local args_fpl = args.fpl
	local args_pl = args[2]

	if is_plurale_tantum and not has_singular then
		if #args_pl > 0 then
			error("Can't specify plurals of plurale tantum " .. pos)
		end
		table.insert(data.inflections, {label = glossary_link("ပါဲနူကိုန်ဗဟုဝစ်")})
	else
		if is_plurale_tantum then
			-- both singular and plural
			table.insert(data.inflections, {label = "sometimes " .. glossary_link("ပါဲနူကိုန်ဗဟုဝစ်") .. ", in variation"})
		end
		-- If no plurals, use the default plural.
		if #args_pl == 0 then
			args_pl = {"+"}
		end
		-- If only ~ given (countable and uncountable), add the default plural after it.
		if #args_pl == 1 and args_pl[1] == "~" then
			args_pl = {"~", "+"}
		end
		-- Gather plurals, handling requests for default plurals
		for i, pl in ipairs(args_pl) do
			local function insert_pl(term)
				local quals = fetch_qualifiers(args.pl_qual[i])
				if term == lemma and i == 1 and #args_pl == 1 then
					table.insert(data.inflections, {label = glossary_link("invariable"), qualifiers = quals})
					table.insert(data.categories, langname .. " indeclinable " .. plpos)
				else
					insert_inflection(plurals, term, nil, quals)
				end
				table.insert(data.categories, plpos .. langname .. "မတော်ဂွံဂမၠိုင်")
			end
			local function make_plural_and_insert(form, special)
				local pl = com.make_plural(lemma, special)
				if pl then
					insert_pl(pl)
				end
			end

			if pl == "+" then
				make_plural_and_insert(lemma)
			elseif pl:find("^%+") then
				pl = require(romut_module).get_special_indicator(pl)
				make_plural_and_insert(lemma, pl)
			elseif pl == "?" or pl == "!" then
				if i > 1 or #args_pl > 1 then
					error("Can't specify ? or ! with other plurals")
				end
				if pl == "?" then
					-- Plural is unknown
					-- Better not to display anything
					-- table.insert(data.inflections, {label = "plural unknown or uncertain"})
					
				else
					-- Plural is not attested
					table.insert(data.inflections, {label = "plural not attested"})
					
				end
			elseif pl == "-" then
				if i > 1 then
					error("Plural specifier - must be first")
				end
				-- Uncountable noun; may occasionally have a plural
				

				-- If plural forms were given explicitly, then show "usually"
				if #args_pl > 1 then
					table.insert(data.inflections, {label = "တော်ဟွံမာန် " .. glossary_link("ဗွဲမဂၠိုၚ်")})
					
				else
					table.insert(data.inflections, {label = glossary_link("uncountable")})
				end
			elseif pl == "~" then
				if i > 1 then
					error("Plural specifier ~ must be first")
				end
				-- Countable and uncountable noun; will have a plural
				
				
				table.insert(data.inflections, {label = glossary_link("countable") .. " and " .. glossary_link("uncountable")})
			else
				insert_pl(replace_hash_with_lemma(pl, lemma))
			end
		end
	end

	if #plurals > 1 then
		
	end

	-- Gather masculines/feminines. For each one, generate the corresponding plural(s).
	local function handle_mf(mfs, qualifiers, inflect, default_plurals)
		local retval = {}
		for i, mf in ipairs(mfs) do
			local function insert_infl(list, term, accel, existing_qualifiers)
				insert_inflection(list, term, accel, fetch_qualifiers(qualifiers[i], existing_qualifiers), "no inv")
			end
			if mf == "+" then
				-- Generate default feminine.
				mf = inflect(lemma)
			else
				mf = replace_hash_with_lemma(mf, lemma)
			end
			local special = require(romut_module).get_special_indicator(mf)
			if special then
				mf = inflect(lemma, special)
			end
			insert_infl(retval, mf)
			local mfpl = com.make_plural(mf, special)
			if mfpl then
				-- Add an accelerator for each masculine/feminine plural whose lemma
				-- is the corresponding singular, so that the accelerated entry
				-- that is generated has a definition that looks like
				-- # {{plural of|pt|MFSING}}
				insert_infl(default_plurals, mfpl, {form = "p", lemma = mf})
			end
		end
		return retval
	end

	local feminine_plurals = {}
	local feminines = handle_mf(args.f, args.f_qual, com.make_feminine, feminine_plurals)
	local masculine_plurals = {}
	local masculines = handle_mf(args.m, args.m_qual, com.make_masculine, masculine_plurals)

	local function handle_mf_plural(mfpl, qualifiers, default_plurals, singulars)
		local new_mfpls = {}
		for i, mfpl in ipairs(mfpl) do
			local function insert_infl(term, accel, existing_qualifiers, no_inv)
				insert_inflection(new_mfpls, term, accel, fetch_qualifiers(qualifiers[i], existing_qualifiers), no_inv)
			end
			local accel
			if #mfpl == #singulars then
				-- If same number of overriding masculine/feminine plurals as singulars,
				-- assume each plural goes with the corresponding singular
				-- and use each corresponding singular as the lemma in the accelerator.
				-- The generated entry will have # {{plural of|pt|SINGULAR}} as the
				-- definition.
				accel = {form = "p", lemma = singulars[i].term}
			else
				accel = nil
			end
			if mfpl == "+" then
				if #default_plurals > 0 then
					for _, defpl in ipairs(default_plurals) do
						-- defpl is a table
						-- don't use "invariable" because the plural is not with respect to the lemma but
						-- with respect to the masc/fem singular
						insert_infl(defpl.term_for_further_inflection, defpl.accel, defpl.qualifiers, "no inv")
					end
				else
					-- mf is a table
					local default_mfpl = com.make_plural(lemma)
					if default_mfpl then
						insert_infl(default_mfpl, accel)
					end
				end
			elseif mfpl:find("^%+") then
				mfpl = require(romut_module).get_special_indicator(mfpl)
				if #singulars > 0 then
					for _, mf in ipairs(singulars) do
						-- mf is a table
						local default_mfpl = com.make_plural(mf.term_for_further_inflection, mfpl)
						if default_mfpl then
							-- don't use "invariable" because the plural is not with respect to the lemma but
							-- with respect to the masc/fem singular
							insert_infl(default_mfpl, accel, mf.qualifiers, "no inv")
						end
					end
				else
					local default_mfpl = com.make_plural(lemma, mfpl)
					if default_mfpl then
						insert_infl(default_mfpl, accel)
					end
				end
			else
				mfpl = replace_hash_with_lemma(mfpl, lemma)
				-- don't use "invariable" if masc/fem singular present because the plural is not with respect to
				-- the lemma but with respect to the masc/fem singular
				insert_infl(mfpl, accel, nil, #singulars > 0)
			end
		end
		return new_mfpls
	end

	if #args_fpl > 0 then
		-- Override feminine plurals.
		feminine_plurals = handle_mf_plural(args_fpl, args.fpl_qual, feminine_plurals, feminines)
	end

	if #args_mpl > 0 then
		-- Override masculine plurals.
		masculine_plurals = handle_mf_plural(args_mpl, args.mpl_qual, masculine_plurals, masculines)
	end

	check_all_missing(plurals, plpos, tracking_categories)
	check_all_missing(feminines, plpos, tracking_categories)
	check_all_missing(feminine_plurals, plpos, tracking_categories)
	check_all_missing(masculines, plpos, tracking_categories)
	check_all_missing(masculine_plurals, plpos, tracking_categories)

	local function redundant_plural(pl)
		for _, p in ipairs(plurals) do
			if p.term_for_further_inflection == pl.term_for_further_inflection then
				return true
			end
		end
		return false
	end

	for _, mpl in ipairs(masculine_plurals) do
		if redundant_plural(mpl) then
			track("noun-redundant-mpl")
		end
	end

	for _, fpl in ipairs(feminine_plurals) do
		if redundant_plural(fpl) then
			track("noun-redundant-fpl")
		end
	end

	if #plurals > 0 then
		plurals.label = "ကိုန်ဗဟုဝစ်"
		plurals.accel = {form = "p"}
		table.insert(data.inflections, plurals)
	end

	if #masculines > 0 then
		masculines.label = "ပုလ္လိင်"
		table.insert(data.inflections, masculines)
	end

	if #masculine_plurals > 0 then
		masculine_plurals.label = "ကိုန်ဗဟုဝစ်ပုလ္လိင်"
		table.insert(data.inflections, masculine_plurals)
	end

	if #feminines > 0 then
		feminines.label = "ဣတ္တိလိင်"
		feminines.accel = {form = "f"}
		table.insert(data.inflections, feminines)
	end

	if #feminine_plurals > 0 then
		feminine_plurals.label = "ကိုန်ဗဟုဝစ်ဣတ္တိလိင်"
		table.insert(data.inflections, feminine_plurals)
	end

	if is_metaphonic(args, lemma) then
		table.insert(data.inflections, {label = metaphonic_label})
		
	end

	-- Maybe add category 'Portuguese nouns with irregular gender' (or similar)
	local irreg_gender_lemma = com.rsub(lemma, " .*", "") -- only look at first word
	if (rfind(irreg_gender_lemma, "[^ã]o$") and (gender_for_default_plural == "f" or gender_for_default_plural == "mf"
		or gender_for_default_plural == "mfbysense")) or
		(irreg_gender_lemma:find("a$") and (gender_for_default_plural == "m" or gender_for_default_plural == "mf"
		or gender_for_default_plural == "mfbysense")) then
		table.insert(data.categories, langname .. " " .. plpos .. " with irregular gender")
	end
end

local function get_noun_params()
	return {
		[1] = {list = "g", required = true, default = "?"},
		[2] = {list = "pl"},
		["g_qual"] = {list = "g=_qual", allow_holes = true},
		["pl_qual"] = {list = "pl=_qual", allow_holes = true},
		["m"] = {list = true},
		["m_qual"] = {list = "m=_qual", allow_holes = true},
		["f"] = {list = true},
		["f_qual"] = {list = "f=_qual", allow_holes = true},
		["mpl"] = {list = true},
		["mpl_qual"] = {list = "mpl=_qual", allow_holes = true},
		["fpl"] = {list = true},
		["fpl_qual"] = {list = "fpl=_qual", allow_holes = true},
		["meta"] = {type = "boolean"}, -- metaphonic
		["nometa"] = {type = "boolean"}, -- explicitly not metaphonic
	}
end

pos_functions["နာမ်"] = {
	params = get_noun_params(),
	func = function(args, data, tracking_categories)
		do_noun(args, data, tracking_categories, "နာမ်")
	end,
}

local function do_pronoun(args, data, tracking_categories, pos)
	local plpos = require("Module:string utilities").pluralize(pos)

	data.pos_category = plpos

	local lemma = m_links.remove_links(data.heads[1]) -- should always be specified

	data.genders = {}
	for i, g in ipairs(args[1]) do
		if g ~= "n" and g ~= "n-p" and not allowed_genders[g] then
			error("Unrecognized gender: " .. g)
		end
		if args.g_qual[i] then
			table.insert(data.genders, {spec = g, qualifiers = {args.g_qual[i]}})
		else
			table.insert(data.genders, g)
		end
	end

	local function do_inflection(forms, quals, label)
		if #forms > 0 then
			local terms = process_terms_with_qualifiers(forms, quals)
			check_all_missing(terms, plpos, tracking_categories)
			terms.label = label
			table.insert(data.inflections, terms)
		end
	end

	do_inflection(args.m, args.m_qual, "ပုလ္လိင်")
	do_inflection(args.f, args.f_qual, "ဣတ္တိလိင်")
	do_inflection(args.sg, args.sg_qual, "ကိုန်ဨကဝုစ်")
	do_inflection(args.pl, args.pl_qual, "ကိုန်ဗဟုဝစ်")
	do_inflection(args.mpl, args.mpl_qual, "ကိုန်ဗဟုဝစ်ပုလ္လိင်")
	do_inflection(args.fpl, args.fpl_qual, "ကိုန်ဗဟုဝစ်ဣတ္တိလိင်")
	do_inflection(args.n, args.n_qual, "နပုလ္လိင်")
end

local function get_pronoun_params()
	local params = {
		[1] = {list = "g"}, --gender(s)
		["g_qual"] = {list = "g=_qual", allow_holes = true},
		["m"] = {list = true}, --masculine form(s)
		["m_qual"] = {list = "m=_qual", allow_holes = true},
		["f"] = {list = true}, --feminine form(s)
		["f_qual"] = {list = "f=_qual", allow_holes = true},
		["sg"] = {list = true}, --singular form(s)
		["sg_qual"] = {list = "sg=_qual", allow_holes = true},
		["pl"] = {list = true}, --plural form(s)
		["pl_qual"] = {list = "pl=_qual", allow_holes = true},
		["mpl"] = {list = true}, --masculine plural form(s)
		["mpl_qual"] = {list = "mpl=_qual", allow_holes = true},
		["fpl"] = {list = true}, --feminine plural form(s)
		["fpl_qual"] = {list = "fpl=_qual", allow_holes = true},
		["n"] = {list = true}, --neuter form(s)
		["n_qual"] = {list = "n=_qual", allow_holes = true},
	}
	return params
end

pos_functions["သဗ္ဗနာမ်"] = {
	params = get_pronoun_params(),
	func = function(args, data, tracking_categories)
		do_pronoun(args, data, tracking_categories, "သဗ္ဗနာမ်")
	end,
}

local function do_adjective(args, data, tracking_categories, pos, is_superlative)
	local feminines = {}
	local masculine_plurals = {}
	local feminine_plurals = {}
	local plpos = require("Module:string utilities").pluralize(pos)

	local romut = require(romut_module)
	data.pos_category = plpos

	if args.sp and not romut.allowed_special_indicators[args.sp] then
		local indicators = {}
		for indic, _ in pairs(romut.allowed_special_indicators) do
			table.insert(indicators, "'" .. indic .. "'")
		end
		table.sort(indicators)
		error("Special inflection indicator beginning can only be " ..
			m_table.serialCommaJoin(indicators, {dontTag = true}) .. ": " .. args.sp)
	end

	local lemma = m_links.remove_links(data.heads[1]) -- should always be specified

	local function insert_inflection(forms, label, accel)
		if #forms > 0 then
			if forms[1].term == "-" then
				table.insert(data.inflections, {label = "no " .. label})
			else
				forms.label = label
				forms.accel = {form = accel}
				table.insert(data.inflections, forms)
			end
		end
	end

	local function insert_ancillary_inflection(forms, quals, label)
		if forms and #forms > 0 then
			local terms = process_terms_with_qualifiers(forms, quals)
			check_all_missing(terms, plpos, tracking_categories)
			terms.label = label
			table.insert(data.inflections, terms)
		end
	end


	if args.inv then
		-- invariable adjective
		table.insert(data.inflections, {label = glossary_link("invariable")})
		table.insert(data.categories, langname .. " indeclinable " .. plpos)
		if args.sp or #args.f > 0 or #args.pl > 0 or #args.mpl > 0 or #args.fpl > 0 then
			error("Can't specify inflections with an invariable adjective")
		end
	elseif args.fonly then
		-- feminine-only
		if #args.f > 0 then
			error("Can't specify explicit feminines with feminine-only adjective")
		end
		if #args.pl > 0 then
			error("Can't specify explicit plurals with feminine-only adjective, use fpl=")
		end
		if #args.mpl > 0 then
			error("Can't specify explicit masculine plurals with feminine-only adjective")
		end
		local argsfpl = args.fpl
		if #argsfpl == 0 then
			argsfpl = {"+"}
		end
		for i, fpl in ipairs(argsfpl) do
			if fpl == "+" then
				local defpl = com.make_plural(lemma, args.sp)
				if not defpl then
					error("Unable to generate default plural of '" .. lemma .. "'")
				end
				fpl = defpl
			else
				fpl = replace_hash_with_lemma(fpl, lemma)
			end
			table.insert(feminine_plurals, {term = fpl, qualifiers = fetch_qualifiers(args.fpl_qual[i])})
		end

		check_all_missing(feminine_plurals, plpos, tracking_categories)

		table.insert(data.inflections, {label = "ပါဲနူ-ဣတ္တိလိင်"})
		insert_inflection(feminine_plurals, "ကိုန်ဗဟုဝစ်ဣတ္တိလိင်", "f|p")
	else
		-- Gather feminines.
		local argsf = args.f
		if #argsf == 0 then
			argsf = {"+"}
		end
		for i, f in ipairs(argsf) do
			if f == "+" then
				-- Generate default feminine.
				f = com.make_feminine(lemma, args.sp)
			else
				f = replace_hash_with_lemma(f, lemma)
			end
			table.insert(feminines, {term = f, qualifiers = fetch_qualifiers(args.f_qual[i])})
		end

		local argsmpl = args.mpl
		local argsfpl = args.fpl
		if #args.pl > 0 then
			if #argsmpl > 0 or #argsfpl > 0 or args.mpl_qual.maxindex > 0 or args.fpl_qual.maxindex > 0 then
				error("Can't specify both pl= and mpl=/fpl=")
			end
			argsmpl = args.pl
			args.mpl_qual = args.pl_qual
			argsfpl = args.pl
			args.fpl_qual = args.pl_qual
		end
		if #argsmpl == 0 then
			argsmpl = {"+"}
		end
		if #argsfpl == 0 then
			argsfpl = {"+"}
		end

		for i, mpl in ipairs(argsmpl) do
			if mpl == "+" then
				-- Generate default masculine plural.
				local defpl = com.make_plural(lemma, args.sp)
				if not defpl then
					error("Unable to generate default plural of '" .. lemma .. "'")
				end
				mpl = defpl
			else
				mpl = replace_hash_with_lemma(mpl, lemma)
			end
			table.insert(masculine_plurals, {term = mpl, qualifiers = fetch_qualifiers(args.mpl_qual[i])})
		end

		for i, fpl in ipairs(argsfpl) do
			if fpl == "+" then
				for _, f in ipairs(feminines) do
					-- Generate default feminine plural; f is a table.
					local defpl = com.make_plural(f.term, args.sp)
					if not defpl then
						error("Unable to generate default plural of '" .. f.term .. "'")
					end
					table.insert(feminine_plurals, {term = defpl, qualifiers = fetch_qualifiers(args.fpl_qual[i], f.qualifiers)})
				end
			else
				fpl = replace_hash_with_lemma(fpl, lemma)
				table.insert(feminine_plurals, {term = fpl, qualifiers = fetch_qualifiers(args.fpl_qual[i])})
			end
		end

		check_all_missing(feminines, plpos, tracking_categories)
		check_all_missing(masculine_plurals, plpos, tracking_categories)
		check_all_missing(feminine_plurals, plpos, tracking_categories)

		local fem_like_lemma = #feminines == 1 and feminines[1].term == lemma and not feminines[1].qualifiers
		local fem_pl_like_masc_pl = #masculine_plurals > 0 and #feminine_plurals > 0 and
			m_table.deepEquals(masculine_plurals, feminine_plurals)
		local masc_pl_like_lemma = #masculine_plurals == 1 and masculine_plurals[1].term == lemma and
			not masculine_plurals[1].qualifiers
		if fem_like_lemma and fem_pl_like_masc_pl and masc_pl_like_lemma then
			-- actually invariable
			table.insert(data.inflections, {label = glossary_link("invariable")})
			table.insert(data.categories, langname .. " indeclinable " .. plpos)
		else
			-- Make sure there are feminines given and not same as lemma.
			if not fem_like_lemma then
				insert_inflection(feminines, "ဣတ္တိလိင်", "f|s")
			end

			if fem_pl_like_masc_pl then
				insert_inflection(masculine_plurals, "ကိုန်ဗဟုဝစ်", "p")
				data.genders = {"mf"}
			else
				insert_inflection(masculine_plurals, "ကိုန်ဗဟုဝစ်ပုလ္လိင်", "m|p")
				insert_inflection(feminine_plurals, "ကိုန်ဗဟုဝစ်ဣတ္တိလိင်", "f|p")
			end
		end
	end

	insert_ancillary_inflection(args.n, args.n_qual, "နပုလ္လိင်")

	if args.hascomp then
		if args.hascomp == "both" then
			table.insert(data.inflections, {label = "sometimes " .. glossary_link("comparable")})
			
			
		else
			local hascomp = require("Module:yesno")(args.hascomp)
			if hascomp == true then
				table.insert(data.inflections, {label = glossary_link("comparable")})
				
			elseif hascomp == false then
				table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
				
			else
				error("Unrecognized value for hascomp=: " .. args.hascomp)
			end
		end
	elseif args.comp and #args.comp > 0 or args.sup and #args.sup > 0 then
		table.insert(data.inflections, {label = glossary_link("comparable")})
		
	end

	insert_ancillary_inflection(args.comp, args.comp_qual, "ပတုပ်ရံၚ်")
	insert_ancillary_inflection(args.sup, args.sup_qual, "သဒ္ဒာ")

	if is_metaphonic(args, lemma) then
		table.insert(data.inflections, {label = metaphonic_label})
		
	end

	if args.irreg and is_superlative then
		
	end
end

local function get_adjective_params(adjtype)
	local params = {
		["inv"] = {type = "boolean"}, --invariable
		["sp"] = {}, -- special indicator: "first", "first-last", etc.
		["f"] = {list = true}, --feminine form(s)
		["f_qual"] = {list = "f=_qual", allow_holes = true},
		["pl"] = {list = true}, --plural override(s)
		["pl_qual"] = {list = "pl=_qual", allow_holes = true},
		["mpl"] = {list = true}, --masculine plural override(s)
		["mpl_qual"] = {list = "mpl=_qual", allow_holes = true},
		["fpl"] = {list = true}, --feminine plural override(s)
		["fpl_qual"] = {list = "fpl=_qual", allow_holes = true},
		["meta"] = {type = "boolean"}, -- metaphonic
		["nometa"] = {type = "boolean"}, -- explicitly not metaphonic
	}
	if adjtype == "base" or adjtype == "part" or adjtype == "det" then
		params["comp"] = {list = true} --comparative(s)
		params["comp_qual"] = {list = "comp=_qual", allow_holes = true}
		params["sup"] = {list = true} --superlative(s)
		params["sup_qual"] = {list = "sup=_qual", allow_holes = true}
		params["fonly"] = {type = "boolean"} -- feminine only
		params["hascomp"] = {} -- has comparative
	end
	if adjtype == "sup" then
		params["irreg"] = {type = "boolean"}
	end
	if adjtype == "pron" then
		params["n"] = {list = true} --neuter form(s)
		params["n_qual"] = {list = "n=_qual", allow_holes = true}
	end
	return params
end

pos_functions["နာမဝိသေသန"] = {
	params = get_adjective_params("base"),
	func = function(args, data, tracking_categories)
		do_adjective(args, data, tracking_categories, "နာမဝိသေသန")
	end,
}

pos_functions["comparative adjectives"] = {
	params = get_adjective_params("comp"),
	func = function(args, data, tracking_categories)
		do_adjective(args, data, tracking_categories, "နာမဝိသေသန")
	end,
}

pos_functions["superlative adjectives"] = {
	params = get_adjective_params("sup"),
	func = function(args, data, tracking_categories)
		do_adjective(args, data, tracking_categories, "နာမဝိသေသန", true)
	end,
}

pos_functions["past participles"] = {
	params = get_adjective_params("part"),
	func = function(args, data, tracking_categories)
		do_adjective(args, data, tracking_categories, "participle")
		data.pos_category = "past participles"
	end,
}

pos_functions["determiners"] = {
	params = get_adjective_params("det"),
	func = function(args, data, tracking_categories)
		do_adjective(args, data, tracking_categories, "determiner")
	end,
}

pos_functions["နာမဝိသေသနညံင်သဗ္ဗနာမ်"] = {
	params = get_adjective_params("pron"),
	func = function(args, data, tracking_categories)
		do_adjective(args, data, tracking_categories, "သဗ္ဗနာမ်")
	end,
}

return export