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

-- Formes irregulars del verb cosir i derivats (descosir, recosir) més tossir.
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)
	local radical = forma.inf:gsub("ir$", "")
	local radical_u = radical:gsub("o", "u")
	local radical_0 = radical_u
	if radical == "toss" then
		radical_0 = "tus"
	elseif radical ~= "cos" then
		radical_0 = radical_u:gsub("us$", "ús")
	end
	
	forma["pres-ind"][1][1] = radical_u .. "o"
	forma["pres-ind"][1][2] = radical_u .. "es"
	forma["pres-ind"][1][3] = radical_0
	forma["pres-ind"][1][6] = radical_u .. "en"

	local fila = 2
	if zona.val or zona.bal or zona.alg then
		forma["pres-ind"][2] = {}
		forma["pres-ind"][2][1] = radical_0
		forma["pres-ind"][2]["nota"] = llista_zones({"bal", "val", "alg"}, zona)
		fila = 3
	end
	if zona.sept then
		forma["pres-ind"][fila] = {}
		forma["pres-ind"][fila][1] = radical_u .. "i"
		forma["pres-ind"][fila]["nota"] = "sept"
	end
	
	forma["pres-subj"][1][1] = radical_u .. "i"
	forma["pres-subj"][1][2] = radical_u .. "is"
	forma["pres-subj"][1][3] = radical_u .. "i"
	forma["pres-subj"][1][6] = radical_u .. "in"
	
	if zona.occ then
		forma["pres-subj"][2][1] = radical_u .. "a"
		forma["pres-subj"][2][2] = radical_u .. "es"
		forma["pres-subj"][2][3] = radical_u .. "a"
		forma["pres-subj"][2][6] = radical_u .. "en"
	end
	
	forma["imp"][1][2] = radical_0
	forma["imp"][1][3] = radical_u .. "i"
	forma["imp"][1][6] = radical_u .. "in"
	
	if zona.occ then
		if zona.bal then fila = 3 else fila = 2 end
		forma["imp"][fila][3] = radical_u .. "a"
		forma["imp"][fila][6] = radical_u .. "en"
	end
	
	if zona.alg then
		forma["no-pres-ind"] = {}
		forma["no-pres-ind"][1] = {}
		forma["no-pres-ind"][1][3] = radical_u .. "i"
		forma["no-pres-ind"][1]["nota"] = "alg"
	end
	
	if zona.occ then
		if radical == "toss" then
			forma["no-pres-subj"] = nil
		else
			forma["no-pres-subj"] = {}
			forma["no-pres-subj"][1] = {}
			forma["no-pres-subj"][1][1] = radical_u .. "ga"
			forma["no-pres-subj"][1][2] = radical_u .. "gues"
			forma["no-pres-subj"][1][3] = radical_u .. "ga"
			forma["no-pres-subj"][1][6] = radical_u .. "guen"
			forma["no-pres-subj"][1]["nota"] = "occ"
			if zona.nocc then
				forma["no-pres-subj"][2] = {}
				forma["no-pres-subj"][2][2] = radical_u .. "gos"
				forma["no-pres-subj"][2][3] = radical_u .. "go"
				forma["no-pres-subj"][2]["nota"] = "n-occ"
			end
		end
	end
	
	fila = 1
	if zona.centr or zona.nocc or zona.bal then
		forma["no-imperf-subj"][1]["nota"] = llista_zones({"centr", "bal", "n-occ"}, zona)
		fila = 2
	end
		
	if zona.alg then
		forma["no-imperf-subj"][fila] = {}
		forma["no-imperf-subj"][fila][1] = radical .. "issi"
		forma["no-imperf-subj"][fila][3] = radical .. "issi"
		forma["no-imperf-subj"][fila]["nota"] = "alg"
		fila = fila + 1
	end
	if zona.val then
		forma["no-imperf-subj"][fila] = nil
	end
	
	return forma
end

return export