local decl = {}

local lang = require("Module:languages").getByCode("la")
local m_links = require("Module:links")
local m_utilities = require("Module:utilities")

local rmatch = mw.ustring.match

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

local function decl_link(english_declension, decl_text)
	decl_text = decl_text or english_declension .. "-declension"
	return "[[Appendix:Latin " .. english_declension .. " declension|" .. decl_text .. "]]"
end

local function singularize(plural)
	-- THIS IS A HACK. We may be passed the word "suffix", where we need to remove
	-- the -es. We also include words ending in -ch or -sh for good measure.
	-- In most other cases we need to remove only the -s.
	if plural:find("xes$") or plural:find("[cs]hes$") then
		return plural:gsub("es$", "")
	else
		return plural:gsub("s$", "")
	end
end

decl["0"] = function(data, args)
	data.title = glossary_link("indeclinable") .. " " .. singularize(data.pos)

	local stem = args[1]

	data.forms["nom_sg_m"] = stem
	data.forms["nom_pl_m"] = stem

	data.forms["gen_sg_m"] = stem
	data.forms["gen_pl_m"] = stem

	data.forms["dat_sg_m"] = stem
	data.forms["dat_pl_m"] = stem

	data.forms["acc_sg_m"] = stem
	data.forms["acc_pl_m"] = stem

	data.forms["abl_sg_m"] = stem
	data.forms["abl_pl_m"] = stem

	data.forms["loc_sg_m"] = stem
	data.forms["loc_pl_m"] = stem

	data.forms["voc_sg_m"] = stem
	data.forms["voc_pl_m"] = stem

	table.insert(data.categories, "Latin indeclinable " .. data.pos)
end

decl["1&2"] = function(data, args)
	local singpos = singularize(data.pos)
	if data.gender == "F" then
		data.title = decl_link("first") .. " " .. singpos
	elseif data.gender then
		data.title = decl_link("second") .. " " .. singpos
	else
		data.title = decl_link("first", "first") .. "/" .. decl_link("second") .. " " .. singpos
	end

	local stem = args[1]
	local original = nil

	if data.types.er then
		if mw.ustring.match(stem, "er$") then
			table.insert(data.subtitles, "nominative masculine singular in ''-er''")
			table.insert(data.categories, "Latin first and second declension "
				.. data.pos .. " with nominative masculine singular in -er")
		elseif mw.ustring.match(stem, "ur$") then
			table.insert(data.subtitles, "nominative masculine singular in ''-ur''")
			table.insert(data.categories, "Latin first and second declension "
				.. data.pos .. " with nominative masculine singular in -ur")
		else
			error("Unrecognized ''-r'' stem (doesn't end in ''-er'' or ''-ur''): " .. stem)
		end
		original = stem
		stem = args[2]
	end

	local us = "us"
	local a_sf = "a"
	local um = "um"
	local ae_gsf = "ae"
	local am = "am"
	local a_macron = "ā"

	if data.types.greekA or data.types.greekE then
		table.insert(data.subtitles, "Greek-type")
		table.insert(data.categories, "Latin first and second declension " ..
			data.pos .. " with Greek declension")
		if data.types.greekA then
			us = "os"
			um = "on"
			am = "ān"
		else
			us = "os"
			a_sf = "ē"
			um = "on"
			ae_gsf = "ēs"
			am = "ēn"
			a_macron = "ē"
		end
	end

	data.forms["nom_sg_m"] = original or (stem .. us)
	data.forms["nom_sg_f"] = stem .. a_sf
	data.forms["nom_sg_n"] = stem .. um
	data.forms["nom_pl_m"] = stem .. "ī"
	data.forms["nom_pl_f"] = stem .. "ae"
	data.forms["nom_pl_n"] = stem .. "a"

	data.forms["gen_sg_m"] = stem .. "ī"
	data.forms["gen_sg_f"] = stem .. ae_gsf
	data.forms["gen_sg_n"] = stem .. "ī"
	data.forms["gen_pl_m"] = stem .. "ōrum"
	data.forms["gen_pl_f"] = stem .. "ārum"
	data.forms["gen_pl_n"] = stem .. "ōrum"

	data.forms["dat_sg_m"] = stem .. "ō"
	data.forms["dat_sg_f"] = stem .. "ae"
	data.forms["dat_sg_n"] = stem .. "ō"
	data.forms["dat_pl_m"] = stem .. "īs"
	data.forms["dat_pl_f"] = stem .. "īs"
	data.forms["dat_pl_n"] = stem .. "īs"

	data.forms["acc_sg_m"] = stem .. um
	data.forms["acc_sg_f"] = stem .. am
	data.forms["acc_sg_n"] = stem .. um
	data.forms["acc_pl_m"] = stem .. "ōs"
	data.forms["acc_pl_f"] = stem .. "ās"
	data.forms["acc_pl_n"] = stem .. "a"

	data.forms["abl_sg_m"] = stem .. "ō"
	data.forms["abl_sg_f"] = stem .. a_macron
	data.forms["abl_sg_n"] = stem .. "ō"
	data.forms["abl_pl_m"] = stem .. "īs"
	data.forms["abl_pl_f"] = stem .. "īs"
	data.forms["abl_pl_n"] = stem .. "īs"

	data.forms["voc_sg_m"] = original or (stem .. "e")
	data.forms["voc_sg_f"] = stem .. a_sf
	data.forms["voc_sg_n"] = stem .. um
	data.forms["voc_pl_m"] = stem .. "ī"
	data.forms["voc_pl_f"] = stem .. "ae"
	data.forms["voc_pl_n"] = stem .. "a"

	data.forms["loc_sg_m"] = stem .. "ī"
	data.forms["loc_sg_f"] = stem .. "ae"
	data.forms["loc_sg_n"] = stem .. "ī"
	data.forms["loc_pl_m"] = stem .. "īs"
	data.forms["loc_pl_f"] = stem .. "īs"
	data.forms["loc_pl_n"] = stem .. "īs"

	if data.types.ius then
		table.insert(data.subtitles, "pronominal")
		--table.insert(data.subtitles, "with genitive singular in ''-ī̆us'' and dative singular in ''-ī''")
		table.insert(data.categories, "Latin first and second declension " ..
			data.pos .. " with genitive singular in -ī̆us")
		data.forms["gen_sg_m"] = stem .. "ī̆us"
		data.forms["gen_sg_f"] = stem .. "ī̆us"
		data.forms["gen_sg_n"] = stem .. "ī̆us"
		data.forms["dat_sg_m"] = stem .. "ī"
		data.forms["dat_sg_f"] = stem .. "ī"
		data.forms["dat_sg_n"] = stem .. "ī"
	elseif data.types.not_ius then
		table.insert(data.subtitles, "non-pronominal")
		--table.insert(data.subtitles, "with normal genitive and dative singular")
	end
	if stem == "me" then
		data.forms["voc_sg_m"] = "mī"
	end
	if data.types.ic then
		table.insert(data.subtitles, "''hic''-type")
		--table.insert(data.subtitles, "with genitive singular ending in ''-ius'' and dative singular ending in ''-ic''")

		local oc = "oc"
		local oc_macron = "ōc"
		if stem == "ill" then
			oc = "uc"
			oc_macron = "ūc"
		end

		data.forms["nom_sg_m"] = stem .. "ic"
		data.forms["nom_sg_f"] = stem .. "aec"
		data.forms["nom_sg_n"] = stem .. oc
		data.forms["nom_pl_n"] = stem .. "aec"

		data.forms["gen_sg_m"] = stem .. "uius"
		data.forms["gen_sg_f"] = stem .. "uius"
		data.forms["gen_sg_n"] = stem .. "uius"

		data.forms["dat_sg_m"] = stem .. "uic"
		data.forms["dat_sg_f"] = stem .. "uic"
		data.forms["dat_sg_n"] = stem .. "uic"

		data.forms["acc_sg_m"] = stem .. "unc"
		data.forms["acc_sg_f"] = stem .. "anc"
		data.forms["acc_sg_n"] = stem .. oc
		data.forms["acc_pl_n"] = stem .. "aec"

		data.forms["abl_sg_m"] = stem .. "ōc"
		data.forms["abl_sg_f"] = stem .. "āc"
		data.forms["abl_sg_n"] = stem .. oc_macron

		data.voc = false
	end

	table.insert(data.categories, "Latin first and second declension " ..
		data.pos)
end

decl["1-1"] = function(data, args)
	data.title = decl_link("first") .. " " .. singularize(data.pos)
	table.insert(data.subtitles, "masculine and neuter forms identical to feminine forms")

	local stem = args[1]

	data.forms["nom_sg_m"] = stem .. "a"
	data.forms["nom_pl_m"] = stem .. "ae"
	data.forms["nom_pl_n"] = stem .. "a"

	data.forms["gen_sg_m"] = stem .. "ae"
	data.forms["gen_pl_m"] = stem .. "ārum"

	data.forms["dat_sg_m"] = stem .. "ae"
	data.forms["dat_pl_m"] = stem .. "īs"

	data.forms["acc_sg_m"] = stem .. "am"
	data.forms["acc_sg_n"] = stem .. "a"
	data.forms["acc_pl_m"] = stem .. "ās"
	data.forms["acc_pl_n"] = stem .. "a"

	data.forms["abl_sg_m"] = stem .. "ā"
	data.forms["abl_pl_m"] = stem .. "īs"

	data.forms["loc_sg_m"] = stem .. "ae"
	data.forms["loc_pl_m"] = stem .. "īs"

	data.forms["voc_sg_m"] = stem .. "a"
	data.forms["voc_pl_m"] = stem .. "ae"

	table.insert(data.categories, "Latin first declension " .. data.pos)
end

decl["2-2"] = function(data, args)
	data.title = decl_link("second") .. " " .. singularize(data.pos)
	table.insert(data.subtitles, "feminine forms identical to masculine forms")

	local stem = args[1]

	local us = "us"
	local um = "um"
	local i_pl = "ī"

	if data.types.greek then
		table.insert(data.subtitles, "Greek-type")
		table.insert(data.categories, "Latin second declension " .. data.pos ..
			" with Greek declension")
		us = "os"
		um = "on"
		i_pl = "oe"
	end

	data.forms["nom_sg_m"] = stem .. us
	data.forms["nom_sg_n"] = stem .. um
	data.forms["nom_pl_m"] = stem .. i_pl
	data.forms["nom_pl_n"] = stem .. "a"

	data.forms["gen_sg_m"] = stem .. "ī"
	data.forms["gen_sg_n"] = stem .. "ī"
	data.forms["gen_pl_m"] = stem .. "ōrum"
	data.forms["gen_pl_n"] = stem .. "ōrum"

	data.forms["dat_sg_m"] = stem .. "ō"
	data.forms["dat_sg_n"] = stem .. "ō"
	data.forms["dat_pl_m"] = stem .. "īs"
	data.forms["dat_pl_n"] = stem .. "īs"

	data.forms["acc_sg_m"] = stem .. um
	data.forms["acc_sg_n"] = stem .. um
	data.forms["acc_pl_m"] = stem .. "ōs"
	data.forms["acc_pl_n"] = stem .. "a"

	data.forms["abl_sg_m"] = stem .. "ō"
	data.forms["abl_sg_n"] = stem .. "ō"
	data.forms["abl_pl_m"] = stem .. "īs"
	data.forms["abl_pl_n"] = stem .. "īs"

	data.forms["loc_sg_m"] = stem .. "ī"
	data.forms["loc_sg_n"] = stem .. "ī"
	data.forms["loc_pl_m"] = stem .. "īs"
	data.forms["loc_pl_n"] = stem .. "īs"

	data.forms["voc_sg_m"] = stem .. "e"
	data.forms["voc_sg_n"] = stem .. um
	data.forms["voc_pl_m"] = stem .. i_pl
	data.forms["voc_pl_n"] = stem .. "a"

	table.insert(data.categories, "Latin second declension " .. data.pos)
end

decl["3-1"] = function(data, args)
	local singpos = singularize(data.pos)
	if data.gender then
		data.title = decl_link("third") .. " " .. singpos
	else
		data.title = decl_link("third") .. " one-termination " .. singpos
	end

	local stem1 = args[1]
	local stem2 = args[2]

	data.forms["nom_sg_m"] = stem1
	data.forms["nom_sg_n"] = stem1
	data.forms["nom_pl_m"] = stem2 .. "ēs"
	data.forms["nom_pl_n"] = stem2 .. "ia"

	data.forms["gen_sg_m"] = stem2 .. "is"
	data.forms["gen_sg_n"] = stem2 .. "is"
	data.forms["gen_pl_m"] = stem2 .. "ium"
	data.forms["gen_pl_n"] = stem2 .. "ium"

	data.forms["dat_sg_m"] = stem2 .. "ī"
	data.forms["dat_sg_n"] = stem2 .. "ī"
	data.forms["dat_pl_m"] = stem2 .. "ibus"
	data.forms["dat_pl_n"] = stem2 .. "ibus"

	data.forms["acc_sg_m"] = stem2 .. "em"
	data.forms["acc_sg_n"] = stem1
	data.forms["acc_pl_m"] = stem2 .. "ēs"
	data.forms["acc_pl_n"] = stem2 .. "ia"

	data.forms["abl_sg_m"] = stem2 .. "ī"
	data.forms["abl_sg_n"] = stem2 .. "ī"
	data.forms["abl_pl_m"] = stem2 .. "ibus"
	data.forms["abl_pl_n"] = stem2 .. "ibus"

	data.forms["loc_sg_m"] = stem2 .. "ī"
	data.forms["loc_sg_n"] = stem2 .. "ī"
	data.forms["loc_pl_m"] = stem2 .. "ibus"
	data.forms["loc_pl_n"] = stem2 .. "ibus"

	data.forms["voc_sg_m"] = stem1
	data.forms["voc_sg_n"] = stem1
	data.forms["voc_pl_m"] = stem2 .. "ēs"
	data.forms["voc_pl_n"] = stem2 .. "ia"

	if data.types.par then
		table.insert(data.subtitles, "non-i-stem")
		data.forms["nom_pl_n"] = stem2 .. "a"
		data.forms["gen_pl_m"] = stem2 .. "um"
		data.forms["gen_pl_n"] = stem2 .. "um"
		data.forms["abl_sg_m"] = stem2 .. "e"
		data.forms["abl_sg_n"] = stem2 .. "e"
		data.forms["loc_sg_m"] = {stem2 .. "ī", stem2 .. "e"}
		data.forms["loc_sg_n"] = {stem2 .. "ī", stem2 .. "e"}
		data.forms["acc_pl_n"] = stem2 .. "a"
		data.forms["voc_pl_n"] = stem2 .. "a"
	elseif data.types.not_par then
		table.insert(data.subtitles, "i-stem")
	end

	local es_base = rmatch(stem1, "^(.*)ēs$")
	if es_base and es_base == stem2 then
		if data.types.greek then
			local note = "It is unknown if Classical Latin preserved (or would have preserved) the shortness of the original Greek short ending."
			data.forms["nom_sg_n"] = {stem2 .. "es", stem2 .. "ēs"}
			data.notes["nom_sg_n1"] = note
			data.forms["acc_sg_n"] = {stem2 .. "es", stem2 .. "ēs"}
			data.notes["acc_sg_n1"] = note
			data.forms["voc_sg_m"] = {stem2 .. "es", stem2 .. "ēs"}
			data.notes["voc_sg_m1"] = note
			data.forms["voc_sg_n"] = {stem2 .. "es", stem2 .. "ēs"}
			data.notes["voc_sg_n1"] = note
			table.insert(data.subtitles, "Greek-type")
		elseif data.types.not_greek then
			table.insert(data.subtitles, "non-Greek-type")
		end
	end

	table.insert(data.categories, "Latin third declension " .. data.pos)
	table.insert(data.categories, "Latin third declension " .. data.pos .. " of one termination")
end

decl["3-C"] = function(data, args)
	local stem = args[1]

	data.types.par = true
	decl["3-1"](data, {stem .. "or", stem .. "ōr"})

	data.title = decl_link("third") .. " comparative " .. singularize(data.pos)
	data.subtitles = {}

	data.forms["nom_sg_n"] = stem .. "us"
	data.forms["acc_sg_n"] = stem .. "us"
	data.forms["voc_sg_n"] = stem .. "us"
end

decl["3-P"] = function(data, args)
	local stem1 = args[1]
	local stem2 = args[2]

	decl["3-1"](data, args)
	data.title = decl_link("third") .. " participle"

	data.forms["abl_sg_m"] = {stem2 .. "e", stem2 .. "ī"}
	data.notes["abl_sg_m2"] = "When used purely as an adjective."
	data.forms["abl_sg_n"] = {stem2 .. "e", stem2 .. "ī"}
	data.notes["abl_sg_n2"] = "When used purely as an adjective."
	data.forms["acc_pl_m"] = {stem2 .. "ēs", stem2 .. "īs"}
end

decl["3-2"] = function(data, args)
	local singpos = singularize(data.pos)
	if data.gender then
		data.title = decl_link("third") .. " " .. singpos
	else
		data.title = decl_link("third") .. " two-termination " .. singpos
	end

	local stem = args[1]
	local stem2 = args[2]

	data.forms["nom_sg_m"] = stem .. "is"
	data.forms["nom_sg_n"] = stem .. "e"
	data.forms["nom_pl_m"] = stem .. "ēs"
	data.forms["nom_pl_n"] = stem .. "ia"

	data.forms["gen_sg_m"] = stem .. "is"
	data.forms["gen_sg_n"] = stem .. "is"
	data.forms["gen_pl_m"] = stem .. "ium"
	data.forms["gen_pl_n"] = stem .. "ium"

	data.forms["dat_sg_m"] = stem .. "ī"
	data.forms["dat_sg_n"] = stem .. "ī"
	data.forms["dat_pl_m"] = stem .. "ibus"
	data.forms["dat_pl_n"] = stem .. "ibus"

	data.forms["acc_sg_m"] = stem .. "em"
	data.forms["acc_sg_n"] = stem .. "e"
	data.forms["acc_pl_m"] = {stem .. "ēs", stem .. "īs"}
	data.forms["acc_pl_n"] = stem .. "ia"

	data.forms["abl_sg_m"] = stem .. "ī"
	data.forms["abl_sg_n"] = stem .. "ī"
	data.forms["abl_pl_m"] = stem .. "ibus"
	data.forms["abl_pl_n"] = stem .. "ibus"

	data.forms["loc_sg_m"] = stem .. "ī"
	data.forms["loc_sg_n"] = stem .. "ī"
	data.forms["loc_pl_m"] = stem .. "ibus"
	data.forms["loc_pl_n"] = stem .. "ibus"

	data.forms["voc_sg_m"] = stem .. "is"
	data.forms["voc_sg_n"] = stem .. "e"
	data.forms["voc_pl_m"] = stem .. "ēs"
	data.forms["voc_pl_n"] = stem .. "ia"

	table.insert(data.categories, "Latin third declension " .. data.pos)
	table.insert(data.categories, "Latin third declension " .. data.pos .. " of two terminations")
end

decl["3-3"] = function(data, args)
	local singpos = singularize(data.pos)
	if data.gender then
		data.title = decl_link("third") .. " " .. singpos
	else
		data.title = decl_link("third") .. " three-termination " .. singpos
	end

	local stem1 = args[1]
	local stem2 = args[2]

	data.forms["nom_sg_m"] = stem1
	data.forms["nom_sg_f"] = stem2 .. "is"
	data.forms["nom_sg_n"] = stem2 .. "e"
	data.forms["nom_pl_m"] = stem2 .. "ēs"
	data.forms["nom_pl_f"] = stem2 .. "ēs"
	data.forms["nom_pl_n"] = stem2 .. "ia"

	data.forms["gen_sg_m"] = stem2 .. "is"
	data.forms["gen_sg_f"] = stem2 .. "is"
	data.forms["gen_sg_n"] = stem2 .. "is"
	data.forms["gen_pl_m"] = stem2 .. "ium"
	data.forms["gen_pl_f"] = stem2 .. "ium"
	data.forms["gen_pl_n"] = stem2 .. "ium"

	data.forms["dat_sg_m"] = stem2 .. "ī"
	data.forms["dat_sg_f"] = stem2 .. "ī"
	data.forms["dat_sg_n"] = stem2 .. "ī"
	data.forms["dat_pl_m"] = stem2 .. "ibus"
	data.forms["dat_pl_f"] = stem2 .. "ibus"
	data.forms["dat_pl_n"] = stem2 .. "ibus"

	data.forms["acc_sg_m"] = stem2 .. "em"
	data.forms["acc_sg_f"] = stem2 .. "em"
	data.forms["acc_sg_n"] = stem2 .. "e"
	data.forms["acc_pl_m"] = stem2 .. "ēs"
	data.forms["acc_pl_f"] = stem2 .. "ēs"
	data.forms["acc_pl_n"] = stem2 .. "ia"

	data.forms["abl_sg_m"] = stem2 .. "ī"
	data.forms["abl_sg_f"] = stem2 .. "ī"
	data.forms["abl_sg_n"] = stem2 .. "ī"
	data.forms["abl_pl_m"] = stem2 .. "ibus"
	data.forms["abl_pl_f"] = stem2 .. "ibus"
	data.forms["abl_pl_n"] = stem2 .. "ibus"

	data.forms["loc_sg_m"] = stem2 .. "ī"
	data.forms["loc_sg_f"] = stem2 .. "ī"
	data.forms["loc_sg_n"] = stem2 .. "ī"
	data.forms["loc_pl_m"] = stem2 .. "ibus"
	data.forms["loc_pl_f"] = stem2 .. "ibus"
	data.forms["loc_pl_n"] = stem2 .. "ibus"

	data.forms["voc_sg_m"] = stem1
	data.forms["voc_sg_f"] = stem2 .. "is"
	data.forms["voc_sg_n"] = stem2 .. "e"
	data.forms["voc_pl_m"] = stem2 .. "ēs"
	data.forms["voc_pl_f"] = stem2 .. "ēs"
	data.forms["voc_pl_n"] = stem2 .. "ia"

	table.insert(data.categories, "Latin third declension " .. data.pos)
	table.insert(data.categories, "Latin third declension " .. data.pos .. " of three terminations")
end

decl["irreg"] = function(data,args)
	if args[1] == "duo" or args[1] == "ambō" then
		local stem = args[1] == "duo" and "du" or "amb"
		data.title = stem == "amb" and glossary_link("irregular") .. " adjective" or "numeral"
		data.num = "pl"

		local stem_with_o = stem .. (stem == "amb" and "ō" or "o")

		data.forms["nom_pl_m"] = stem_with_o
		data.forms["nom_pl_f"] = stem .. "ae"
		data.forms["nom_pl_n"] = stem_with_o

		data.forms["gen_pl_m"] = stem .. "ōrum"
		data.forms["gen_pl_f"] = stem .. "ārum"
		data.forms["gen_pl_n"] = stem .. "ōrum"

		data.forms["dat_pl_m"] = stem .. "ōbus"
		data.forms["dat_pl_f"] = stem .. "ābus"
		data.forms["dat_pl_n"] = stem .. "ōbus"

		data.forms["acc_pl_m"] = {stem .. "ōs", stem_with_o}
		data.forms["acc_pl_f"] = stem .. "ās"
		data.forms["acc_pl_n"] = stem_with_o

		data.forms["abl_pl_m"] = stem .. "ōbus"
		data.forms["abl_pl_f"] = stem .. "ābus"
		data.forms["abl_pl_n"] = stem .. "ōbus"

		data.forms["voc_pl_m"] = stem_with_o
		data.forms["voc_pl_f"] = stem .. "ae"
		data.forms["voc_pl_n"] = stem_with_o

		if stem == "du" then
			data.footnote = "Note: The genitive masculine and neuter can also be found in the contracted form ''[[duum]]'' (also spelt ''[[duûm]]'')."
		end

	elseif args[1] == "mīlle" then
		data.title = "semi-" .. glossary_link("indeclinable") .. " numeral"
		data.forms["nom_sg_m"] = "mīlle"
		data.forms["nom_pl_m"] = {"mīlia", "mīllia"}

		data.forms["gen_sg_m"] = "mīlle"
		data.forms["gen_pl_m"] = {"mīlium", "mīllium"}

		data.forms["dat_sg_m"] = "mīlle"
		data.forms["dat_pl_m"] = {"mīlibus", "mīllibus"}

		data.forms["acc_sg_m"] = "mīlle"
		data.forms["acc_pl_m"] = {"mīlia", "mīllia"}

		data.forms["abl_sg_m"] = "mīlle"
		data.forms["abl_pl_m"] = {"mīlibus", "mīllibus"}

		data.forms["voc_sg_m"] = "mīlle"
		data.forms["voc_pl_m"] = {"mīlia", "mīllia"}

	elseif args[1] == "illic" then
		data.title = glossary_link("demonstrative") .. " pronoun"

		data.forms["nom_sg_m"] = "illic"
		data.forms["nom_sg_f"] = "illaec"
		data.forms["nom_sg_n"] = {"illuc", "illoc"}
		data.forms["nom_pl_m"] = ""
		data.forms["nom_pl_f"] = ""
		data.forms["nom_pl_n"] = "illaec"

		data.forms["gen_sg_m"] = ""
		data.forms["gen_sg_f"] = ""
		data.forms["gen_sg_n"] = ""
		data.forms["gen_pl_m"] = ""
		data.forms["gen_pl_f"] = ""
		data.forms["gen_pl_n"] = ""

		data.forms["dat_sg_m"] = ""
		data.forms["dat_sg_f"] = ""
		data.forms["dat_sg_n"] = ""
		data.forms["dat_pl_m"] = ""
		data.forms["dat_pl_f"] = ""
		data.forms["dat_pl_n"] = ""

		data.forms["acc_sg_m"] = "illunc"
		data.forms["acc_sg_f"] = "illanc"
		data.forms["acc_sg_n"] = {"illuc", "illoc"}
		data.forms["acc_pl_m"] = ""
		data.forms["acc_pl_f"] = ""
		data.forms["acc_pl_n"] = "illaec"

		data.forms["abl_sg_m"] = "illōc"
		data.forms["abl_sg_f"] = "illāc"
		data.forms["abl_sg_n"] = "illōc"
		data.forms["abl_pl_m"] = ""
		data.forms["abl_pl_f"] = ""
		data.forms["abl_pl_n"] = ""

		data.voc = false

	elseif args[1] == "hice" then
		data.title = glossary_link("demonstrative") .. " pronoun"

		data.forms["nom_sg_m"] = "hice"
		data.forms["nom_sg_f"] = "haece"
		data.forms["nom_sg_n"] = "hoce"
		data.forms["nom_pl_m"] = "hīce"
		data.forms["nom_pl_f"] = "haece"
		data.forms["nom_pl_n"] = "haece"

		data.forms["gen_sg_m"] = "huiusce"
		data.forms["gen_sg_f"] = "huiusce"
		data.forms["gen_sg_n"] = "huiusce"
		data.forms["gen_pl_m"] = {"hōrunce", "hōrumce"}
		data.forms["gen_pl_f"] = {"hārunce", "hārumce"}
		data.forms["gen_pl_n"] = {"hōrunce", "hōrumce"}

		data.forms["dat_sg_m"] = "huīce"
		data.forms["dat_sg_f"] = "huīce"
		data.forms["dat_sg_n"] = "huīce"
		data.forms["dat_pl_m"] = "hīsce"
		data.forms["dat_pl_f"] = "hīsce"
		data.forms["dat_pl_n"] = "hīsce"

		data.forms["acc_sg_m"] = "hunce"
		data.forms["acc_sg_f"] = "hance"
		data.forms["acc_sg_n"] = "hoce"
		data.forms["acc_pl_m"] = "hōsce"
		data.forms["acc_pl_f"] = "hāsce"
		data.forms["acc_pl_n"] = "haece"

		data.forms["abl_sg_m"] = "hōce"
		data.forms["abl_sg_f"] = "hāce"
		data.forms["abl_sg_n"] = "hōce"
		data.forms["abl_pl_m"] = "hīsce"
		data.forms["abl_pl_f"] = "hīsce"
		data.forms["abl_pl_n"] = "hīsce"

		data.voc = false

	elseif args[1] == "plūs" then
		data.title = glossary_link("irregular") .. " " .. decl_link("third") .. " comparative adjective"

		data.forms["nom_sg_m"] = ""
		data.forms["nom_sg_n"] = "plūs"
		data.forms["nom_pl_m"] = "plūrēs"
		data.forms["nom_pl_n"] = "plūra"

		data.forms["gen_sg_m"] = ""
		data.forms["gen_sg_n"] = "plūris"
		data.forms["gen_pl_m"] = "plūrium"
		data.forms["gen_pl_n"] = "plūrium"

		data.forms["dat_sg_m"] = ""
		data.forms["dat_sg_n"] = ""
		data.forms["dat_pl_m"] = "plūribus"
		data.forms["dat_pl_n"] = "plūribus"

		data.forms["acc_sg_m"] = ""
		data.forms["acc_sg_n"] = "plūs"
		data.forms["acc_pl_m"] = "plūrēs"
		data.forms["acc_pl_n"] = "plūra"

		data.forms["abl_sg_m"] = ""
		data.forms["abl_sg_n"] = "plūre"
		data.forms["abl_pl_m"] = "plūribus"
		data.forms["abl_pl_n"] = "plūribus"

		data.forms["voc_sg_m"] = ""
		data.forms["voc_sg_n"] = "plūs"
		data.forms["voc_pl_m"] = "plūrēs"
		data.forms["voc_pl_n"] = "plūra"

		data.footnote = "Note: Singular forms take the genitive of the whole and do not function as adjectives."

		table.insert(data.categories, "Latin third declension " .. data.pos)
		table.insert(data.categories, "Latin third declension " .. data.pos .. " of one termination")
	elseif args[1] == "is" or args[1] == "īdem" then
		data.title = glossary_link("demonstrative") .. " pronoun"

		local note1 = "The dat. singular is found spelled <small>EIEI</small> (here represented as ''ēī'') and scanned as two longs in Plautus, but also as a monosyllable. The latter is its normal scansion in Classical. Other spellings include <small>EEI, IEI</small>."

		local note2 = "The nom./dat./abl. plural forms regularly developed into a monosyllable  /iː(s)/, with later remodelling - compare the etymology of [[deus]]. This /iː/ was normally spelled as <small>EI</small> during and as <small>II</small> after the Republic; a disyllabic ''iī'', spelled <small>II, Iꟾ</small>, apears in Silver Age poetry, while disyllabic ''eīs'' is only post-Classical. Other spellings include <small>EEI(S), EIEI(S), IEI(S)</small>."


		data.forms["nom_sg_m"] = "is"
		data.forms["nom_sg_f"] = "ea"
		data.forms["nom_sg_n"] = "id"
		data.forms["nom_pl_m"] = {"ī", "iī", "eī"}
		data.notes["nom_pl_m1"] = note2
		data.forms["nom_pl_f"] = "eae"
		data.forms["nom_pl_n"] = "ea"

		data.forms["gen_sg_m"] = "eius"
		data.forms["gen_sg_f"] = "eius"
		data.forms["gen_sg_n"] = "eius"
		data.forms["gen_pl_m"] = "eōrum"
		data.forms["gen_pl_f"] = "eārum"
		data.forms["gen_pl_n"] = "eōrum"


		data.forms["dat_sg_m"] = {"ei", "ēī"}
		data.notes["dat_sg_m1"] = note1
		data.forms["dat_sg_f"] = {"ei", "ēī"}
		data.notes["dat_sg_f1"] = note1
		data.forms["dat_sg_n"] = {"ei", "ēī"}
		data.notes["dat_sg_n1"] = note1
		data.forms["dat_pl_m"] = {"īs", "iīs", "eīs"}
		data.notes["dat_pl_m1"] = note2
		data.forms["dat_pl_f"] = {"īs", "iīs", "eīs"}
		data.notes["dat_pl_f1"] = note2
		data.forms["dat_pl_n"] = {"īs", "iīs", "eīs"}
		data.notes["dat_pl_n1"] = note2

		data.forms["acc_sg_m"] = "eum"
		data.forms["acc_sg_f"] = "eam"
		data.forms["acc_sg_n"] = "id"
		data.forms["acc_pl_m"] = "eōs"
		data.forms["acc_pl_f"] = "eās"
		data.forms["acc_pl_n"] = "ea"

		data.forms["abl_sg_m"] = "eō"
		data.forms["abl_sg_f"] = "eā"
		data.forms["abl_sg_n"] = "eō"
		data.forms["abl_pl_m"] = {"īs", "iīs", "eīs"}
		data.notes["abl_pl_m1"] = note2
		data.forms["abl_pl_f"] = {"īs", "iīs", "eīs"}
		data.notes["abl_pl_f1"] = note2
		data.forms["abl_pl_n"] = {"īs", "iīs", "eīs"}
		data.notes["abl_pl_n1"] = note2

		data.voc = false

		if args[1] == "īdem" then
			data.forms["nom_sg_m"] = "ī"
			data.forms["nom_sg_n"] = "i"
			data.forms["nom_pl_m"] = "ī"

			data.forms["gen_pl_m"] = {"eōrun", "eōrum"}
			data.forms["gen_pl_f"] = {"eārun", "eārum"}
			data.forms["gen_pl_n"] = {"eōrun", "eōrum"}

			data.forms["acc_sg_m"] = {"eun", "eum"}
			data.forms["acc_sg_f"] = {"ean", "eam"}
			data.forms["acc_sg_n"] = "i"
		end
	elseif args[1] == "ille" then
		data.types.ius = true

		decl["1&2"](data, {"ill"})

		data.title = glossary_link("demonstrative") .. " pronoun"

		data.forms["nom_sg_m"] = "ille"
		data.forms["nom_sg_n"] = "illud"

		data.forms["acc_sg_n"] = "illud"

		data.voc = false

		data.categories = {}
	elseif args[1] == "iste" then
		data.types.ius = true

		decl["1&2"](data, {"ist"})

		data.title = glossary_link("demonstrative") .. " pronoun"

		data.forms["nom_sg_m"] = "iste"
		data.forms["nom_sg_n"] = "istud"

		data.forms["acc_sg_n"] = "istud"

		data.voc = false

		data.categories = {}
	elseif args[1] == "ipse" then
		data.types.ius = true

		decl["1&2"](data, {"ips"})

		data.title = glossary_link("demonstrative") .. " pronoun"

		data.forms["nom_sg_m"] = "ipse"
		data.forms["nom_sg_n"] = "ipsum"

		data.forms["acc_sg_n"] = "ipsum"

		data.voc = false

		data.categories = {}
	elseif args[1] == "quis" or args[1] == "quī" then

		local note1 = "When used as an indefinite pronoun or adjective, the feminine nominative singular and neuter nominative/accusative plural is usually ''qua'' instead of ''quae''. Indefinite ''qua'' is generally only found directly after the accompanying ''[[si#Latin|sī]]'', ''[[nisi#Latin|nisi]]'', ''[[num#Latin|num]]'', or ''[[ne#Latin|nē]]'' and may be considered to be either enclitic to it or forming a compound with it; sometimes ''[[siqua#Latin|sīqua]]'', ''[[numqua#Latin|numqua]]'', and ''[[nequa#Latin|nēqua]]'' are written together. The form ''qua'' is never found for any form of the interrogative or relative pronouns, nor for the feminine plural of the indefinite pronoun or adjective."

		local note2 = "In Republican Latin or earlier, ''quī'' was often spelled as ''[[quei]]'', ''cuius'' as ''[[quoius]]'', ''cui'' as ''[[quoi]]'' (or ''[[quoiei]]''), and ''quīs'' as ''[[queis]]''."

		local id = "id"
		if args[1] == "quī" then
			id = "od"
			data.forms["nom_sg_m"] = {"quī", "quis"}
			data.notes["nom_sg_m1"] = note2
			data.forms["nom_sg_f"] = {"quae", "qua"}
			data.notes["nom_sg_f2"] = note1
			data.forms["acc_sg_f"] = "quam"
			data.forms["abl_sg_m"] = "quō"
			data.forms["abl_sg_f"] = "quā"
			data.forms["abl_sg_n"] = "quō"
		else
			data.forms["nom_sg_m"] = {"quis", "quī"}
			data.notes["nom_sg_m2"] = note2
			data.forms["nom_sg_f"] = {"quae", "qua", "quis"}
			data.notes["nom_sg_f2"] = note1
			data.forms["acc_sg_f"] = {"quam", "quem"}
			data.forms["abl_sg_m"] = {"quō", "quī"}
			data.forms["abl_sg_f"] = {"quā", "quī"}
			data.forms["abl_sg_n"] = {"quō", "quī"}
		end
		data.title = glossary_link("relative") .. "/" .. glossary_link("interrogative") .. " pronoun"

		data.forms["nom_sg_n"] = "qu"..id
		data.forms["nom_pl_m"] = "quī"
		data.notes["nom_pl_m1"] = note2
		data.forms["nom_pl_f"] = "quae"
		data.forms["nom_pl_n"] = {"quae", "qua"}
		data.notes["nom_pl_n2"] = note1

		data.forms["gen_sg_m"] = "cuius"
		data.forms["gen_sg_f"] = "cuius"
		data.forms["gen_sg_n"] = "cuius"
		data.notes["gen_sg_m1"] = note2
		data.notes["gen_sg_f1"] = note2
		data.notes["gen_sg_n1"] = note2
		data.forms["gen_pl_m"] = "quōrum"
		data.forms["gen_pl_f"] = "quārum"
		data.forms["gen_pl_n"] = "quōrum"

		data.forms["dat_sg_m"] = "cui"
		data.forms["dat_sg_f"] = "cui"
		data.forms["dat_sg_n"] = "cui"
		data.notes["dat_sg_m1"] = note2
		data.notes["dat_sg_f1"] = note2
		data.notes["dat_sg_n1"] = note2
		data.forms["dat_pl_m"] = {"quibus", "quīs"}
		data.forms["dat_pl_f"] = {"quibus", "quīs"}
		data.forms["dat_pl_n"] = {"quibus", "quīs"}
		data.notes["dat_pl_m2"] = note2
		data.notes["dat_pl_f2"] = note2
		data.notes["dat_pl_n2"] = note2

		data.forms["acc_sg_m"] = "quem"
		data.forms["acc_sg_n"] = "qu"..id
		data.forms["acc_pl_m"] = "quōs"
		data.forms["acc_pl_f"] = "quās"
		data.forms["acc_pl_n"] = {"quae", "qua"}
		data.notes["acc_pl_n2"] = note1

		data.forms["abl_pl_m"] = {"quibus", "quīs"}
		data.forms["abl_pl_f"] = {"quibus", "quīs"}
		data.forms["abl_pl_n"] = {"quibus", "quīs"}
		data.notes["abl_pl_m2"] = note2
		data.notes["abl_pl_f2"] = note2
		data.notes["abl_pl_n2"] = note2

		data.voc = false


	elseif args[1] == "quisquis" then
		data.title = glossary_link("relative") .. "/" .. glossary_link("interrogative") .. " pronoun"

		data.forms["nom_sg_m"] = "quisquis"
		data.forms["nom_sg_f"] = "quisquis"
		data.forms["nom_sg_n"] = {"quidquid", "quicquid"}
		data.forms["nom_pl_m"] = "quīquī"
		data.forms["nom_pl_f"] = "quaequae"
		data.forms["nom_pl_n"] = "quaequae"

		data.forms["gen_sg_m"] = "cuiuscuius"
		data.forms["gen_sg_f"] = "cuiuscuius"
		data.forms["gen_sg_n"] = "cuiuscuius"
		data.forms["gen_pl_m"] = "quōrumquōrum"
		data.forms["gen_pl_f"] = "quārumquārum"
		data.forms["gen_pl_n"] = "quōrumquōrum"

		data.forms["dat_sg_m"] = "cuicui"
		data.forms["dat_sg_f"] = "cuicui"
		data.forms["dat_sg_n"] = "cuicui"
		data.forms["dat_pl_m"] = {"quibusquibus", "quīsquīs"}
		data.forms["dat_pl_f"] = {"quibusquibus", "quīsquīs"}
		data.forms["dat_pl_n"] = {"quibusquibus", "quīsquīs"}

		data.forms["acc_sg_m"] = "quemquem"
		data.forms["acc_sg_f"] = "quamquam"
		data.forms["acc_sg_n"] = {"quidquid", "quicquid"}
		data.forms["acc_pl_m"] = "quōsquōs"
		data.forms["acc_pl_f"] = "quāsquās"
		data.forms["acc_pl_n"] = "quaequae"

		data.forms["abl_sg_m"] = "quōquō"
		data.forms["abl_sg_f"] = "quāquā"
		data.forms["abl_sg_n"] = "quōquō"
		data.forms["abl_pl_m"] = {"quibusquibus", "quīsquīs"}
		data.forms["abl_pl_f"] = {"quibusquibus", "quīsquīs"}
		data.forms["abl_pl_n"] = {"quibusquibus", "quīsquīs"}

		data.forms["voc_sg_m"] = "quisquis"
		data.forms["voc_sg_f"] = "quisquis"
		data.forms["voc_sg_n"] = {"quidquid", "quicquid"}
		data.forms["voc_pl_m"] = "quīquī"
		data.forms["voc_pl_f"] = "quaequae"
		data.forms["voc_pl_n"] = "quaequae"

		data.voc = true
	else
		error('adjective ' .. args[1] .. ' not recognized')
	end
end

return decl

-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet:
"https://si.wiktionary.org/w/index.php?title=Module:la-adj/data&oldid=28917" වෙතින් සම්ප්‍රවේශනය කෙරිණි