La documentació d'ús d'aquest mòdul es pot crear a Mòdul:ca-verb/mantenir/ús

-- Formes irregulars dels verbs -tenir i -tindre, més -venir i -vindre.
local export = {}

local function llista_zones(llista, zona)
	local zones = {}
	for k, v in pairs(llista) do
		if zona[v == "or" and "ori" or v == "n-occ" and "nocc" or v] then
			table.insert(zones, v)
		end
	end
	return #zones > 3 and "" or table.concat(zones, ", ")
end

function export.make_irregulars(forma, zona, infinitiu)
	local radical = forma.inf:gsub("ir$", "")
	local radical_i = radical:gsub("en$", "in")
	if forma.inf:find("dre$") then
		radical_i = forma.inf:gsub("dre$", "")
		radical = radical_i:gsub("in$", "en")
	end
	local radical_diacritic = radical
	if radical == "ven" or radical == "reven" then
		radical_diacritic = radical:gsub("ven$", "vén")
	end
	
	forma.inf = infinitiu
	
	forma.ger[1][1] = radical .. "int"
	
	if zona.bal or zona.alg then
		forma.part[2] = {}
		forma.part[2]["m-s"] = radical .. "gut"
		forma.part[2]["f-s"] = radical .. "guda"
		forma.part[2]["m-p"] = radical .. "guts"
		forma.part[2]["f-p"] = radical .. "gudes"
		forma.part[2]["nota"] = llista_zones({"bal", "alg"}, zona)
	end
	
	forma["pres-ind"][1][2] = radical_diacritic .. "s"
	forma["pres-ind"][1][3] = radical == "ven" and "ve" or radical:gsub("en$", "é")
	forma["pres-ind"][1][4] = radical .. "im"
	forma["pres-ind"][1][5] = radical .. "iu"
	forma["pres-ind"][1][6] = radical_diacritic .. "en"
	
	if zona.bal or zona.alg then
		forma["pres-ind"][2] = {}
		forma["pres-ind"][2][1] = radical_diacritic .. "c"
		forma["pres-ind"][2]["nota"] = llista_zones({"bal", "alg"}, zona)
	end
	
	forma["imperf-ind"][1][1] = radical .. "ia"
	forma["imperf-ind"][1][2] = radical .. "ies"
	forma["imperf-ind"][1][3] = radical .. "ia"
	forma["imperf-ind"][1][4] = radical .. "íem"
	forma["imperf-ind"][1][5] = radical .. "íeu"
	forma["imperf-ind"][1][6] = radical .. "ien"
	
	local fila = 1
	if zona.sept or zona.centr or zona.occ then
		fila = fila + 1
	end
	if zona.bal then
		forma["pass"][fila] = {}
		forma["pass"][fila][1] = radical .. "guí"
		forma["pass"][fila][2] = radical .. "gueres"
		forma["pass"][fila][3] = radical .. "gué"
		forma["pass"][fila][4] = radical .. "guérem"
		forma["pass"][fila][5] = radical .. "guéreu"
		forma["pass"][fila][6] = radical .. "gueren"
		forma["pass"][fila]["nota"] = "bal"
	end
	
	fila = 1
	if zona.sept or zona.centr or zona.occ then
		fila = fila + 1
	end
	if zona.bal then
		forma["fut"][fila] = {}
		forma["fut"][fila][1] = radical .. "dré"
		forma["fut"][fila][2] = radical .. "dràs"
		forma["fut"][fila][3] = radical .. "drà"
		forma["fut"][fila][4] = radical .. "drem"
		forma["fut"][fila][5] = radical .. "dreu"
		forma["fut"][fila][6] = radical .. "dran"
		forma["fut"][fila]["nota"] = "bal"
	end
	
	fila = 1
	if zona.sept or zona.centr or zona.occ then
		fila = fila + 1
	end
	if zona.bal then
		forma["cond"][fila] = {}
		forma["cond"][fila][1] = radical .. "dria"
		forma["cond"][fila][2] = radical .. "dries"
		forma["cond"][fila][3] = radical .. "dria"
		forma["cond"][fila][4] = radical .. "dríem"
		forma["cond"][fila][5] = radical .. "dríeu"
		forma["cond"][fila][6] = radical .. "drien"
		forma["cond"][fila]["nota"] = "bal"
	end
	
	fila = 1
	if zona.centr or zona.sept then
		fila = fila + 1
	end
	if zona.occ then
		forma["pres-subj"][fila]["nota"] = "occ"
		fila = fila + 1
	end
	if zona.bal or zona.alg then
		forma["pres-subj"][fila] = {}
		forma["pres-subj"][fila][1] = radical_diacritic .. "gui"
		forma["pres-subj"][fila][2] = radical_diacritic .. "guis"
		forma["pres-subj"][fila][3] = radical_diacritic .. "gui"
		forma["pres-subj"][fila][4] = radical .. "guem"
		forma["pres-subj"][fila][5] = radical .. "gueu"
		forma["pres-subj"][fila][6] = radical_diacritic .. "guin"
		forma["pres-subj"][fila]["nota"] = llista_zones({"bal", "alg"}, zona)
	end
	
	if zona.bal or zona.alg then
		fila = #forma["imperf-subj"] + 1
		forma["imperf-subj"][fila] = {}
		forma["imperf-subj"][fila][1] = radical .. "gués"
		forma["imperf-subj"][fila][2] = radical .. "guessis"
		forma["imperf-subj"][fila][3] = radical .. "gués"
		forma["imperf-subj"][fila][4] = radical .. "guéssim"
		forma["imperf-subj"][fila][5] = radical .. "guéssiu"
		forma["imperf-subj"][fila][6] = radical .. "guessin"
		forma["imperf-subj"][fila]["nota"] = llista_zones({"bal", "alg"}, zona)
	end
	
	if radical:find("ven$") then
		forma["imp"][1][2] = radical == "ven" and "vine" or radical:gsub("ven$", "vén")
		forma["imp"][1][5] = radical .. "iu"
	else
		forma["imp"][1][2] = radical_i .. "gues"
		forma["imp"][1][5] = radical_i .. "gueu"
	end

	fila = 2
	if radical:find("ten$") then
		forma["imp"][2] = {}
		forma["imp"][2][2] = radical == "ten" and "ten" or radical:gsub("ten$", "tén")
		forma["imp"][2][5] = radical .. "iu"
		fila = 3
	end
	
	if zona.occ then
		forma["imp"][fila] = {}
		if radical:find("ten$") then
			forma["imp"][fila][2] = radical == "ten" and "tin" or radical:gsub("en$", "ín")
		end
		forma["imp"][fila][3] = radical_i .. "ga"
		forma["imp"][fila][6] = radical_i .. "guen"
		forma["imp"][fila]["nota"] = "occ"
		fila = fila + 1
	end
	if zona.bal then
		forma["imp"][fila] = {}
		if radical:find("ten$") then
			forma["imp"][fila][2] = radical:gsub("ten$", "té")
		end
		forma["imp"][fila][3] = radical_diacritic .. "gui"
		forma["imp"][fila][4] = radical .. "guem"
		if radical:find("ten$") then
			forma["imp"][fila][5] = radical .. "gueu"
		end
		forma["imp"][fila][6] = radical_diacritic .. "guin"
		forma["imp"][fila]["nota"] = "bal"
	end
	
	forma["no-imperf-ind"] = nil
	if (zona.nocc and zona.alt) or zona.alg then
		forma["no-imperf-ind"] = {}
		forma["no-imperf-ind"][1] = {}
		forma["no-imperf-ind"][1][1] = radical .. "iva"
		forma["no-imperf-ind"][1][2] = radical .. "ives"
		forma["no-imperf-ind"][1][3] = radical .. "iva"
		forma["no-imperf-ind"][1][4] = radical .. "ívem"
		forma["no-imperf-ind"][1][5] = radical .. "íveu"
		forma["no-imperf-ind"][1][6] = radical .. "iven"
		forma["no-imperf-ind"][1]["nota"] = llista_zones({"n-occ", "alg"}, zona)
	end
	
	if zona.alg then
		for k, v in ipairs(forma["no-fut"]) do
			for index, valor in ipairs(forma["no-fut"][k]) do
				forma["no-fut"][k][index] = valor:gsub("ing", "eng")
			end
		end
		for k, v in ipairs(forma["no-cond"]) do
			for index, valor in ipairs(forma["no-cond"][k]) do
				forma["no-cond"][k][index] = valor:gsub("ing", "eng")
			end
		end
	end
	
	if zona.alg then
		forma["no-imperf-subj"] = {}
		forma["no-imperf-subj"][1] = {}
		forma["no-imperf-subj"][1][1] = radical .. "guessi"
		forma["no-imperf-subj"][1][3] = radical .. "guessi"
		forma["no-imperf-subj"][1]["nota"] = "alg"
	else
		forma["no-imperf-subj"] = nil
	end
	
	if radical == "ten" then
		forma.nota = "L'imperatiu «teniu» s'usa quan no hi ha un complement explícit.<br />L'imperatiu «té», d'àmbit general, s'usa sense pronoms febles."
	end
	
	return forma
end

return export