local m_utilities = require("Module:utilities")
local m_links = require("Module:links")

local lang = require("Module:languages").getByCode("nl")

local export = {}

-- Functions that do the actual inflecting by creating the forms of a basic term.
local inflections = {}
local irregular = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local infl_type = frame.args[1] or error("Inflection type has not been specified. Please pass parameter 1 to the module invocation.")
	
	if not inflections[infl_type] then
		error("Unknown inflection type '" .. infl_type .. "'")
	end
	
	local params = {
		["aux"] = {},
		["aux2"] = {},
		["bot"] = {type = "boolean"},
		["pref"] = {},
		["sep"] = {},
		["trans"] = {},
		["trans2"] = {},
		["vnoun"] = {},
		["vnoung"] = {},
		["vnoun2"] = {},
	}
	
	for key, val in pairs(inflections[infl_type].params) do
		params[key] = val
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {forms = {}, title = nil, categories = {}}
	
	inflections[infl_type].func(args, data)
	postprocess(args, data)
	
	if (args["bot"] or "") ~= "" then
		return make_bot_list(data, args["sep"])
	else
		return make_table(data, args["sep"]) .. m_utilities.format_categories(data.categories, lang)
	end
end

function postprocess(args, data)
	-- Verbal noun
	local vnoun = args["vnoun"]
	local vnoun2 = args["vnoun2"]
	
	if vnoun then
		data.forms["vnoun"] = {vnoun, vnoun2}
	end
	
	-- Prefixed and separable
	local pref = args["pref"]
	local sep = args["sep"]
	
	if pref then
		table.insert(data.categories, "荷蘭語不可分動詞") --原作Dutch prefixed verbs帶前綴動詞,但荷蘭語詞典給的是onscheidbaar werkwoord
	--	table.insert(data.categories, "Dutch prefixed verbs with " .. pref .. "-")
		data.title = data.title .. ",不可分"
	end
	
	if sep then
		table.insert(data.categories, "荷蘭語可分動詞")
	--	table.insert(data.categories, "Dutch separable verbs with " .. sep)
		data.title = data.title .. ",可分"
	end
	
	if not pref and not sep then
		table.insert(data.categories, "荷蘭語動詞") --應作Dutch basic verbs,請補充翻譯
	end
	
	add_pref(data, pref)
	add_sep(data, sep)
	
	data.aux = args["aux"] or "hebben"
	
	if args["aux"] then
		if args["aux"] == "zijn" then
			require("Module:debug").track("nl-verb/zijn")
		else
			require("Module:debug").track("nl-verb/aux")
		end
	end
	
	if args["aux2"] then
		require("Module:debug").track("nl-verb/aux2")
	end
	
	data.trans = args["trans"]
	
	if data.trans then
		if data.trans == "acc" then
			table.insert(data.categories, "荷蘭語賓格動詞")
		elseif data.trans == "erg" then
			table.insert(data.categories, "荷蘭語作格動詞")
		elseif data.trans == "unerg" then
			table.insert(data.categories, "荷蘭語非作格動詞")
		elseif data.trans == "unacc" then
			table.insert(data.categories, "荷蘭語非賓格動詞")
		else
			error("The \"trans=\" parameter has an invalid value. Valid are: acc, erg, unerg, unacc.")
		end
	end
	
	data.trans2 = args["trans2"]
	
	if data.trans2 then
		if data.trans2 == "acc" then
			table.insert(data.categories, "荷蘭語賓格動詞")
		elseif data.trans2 == "erg" then
			table.insert(data.categories, "荷蘭語作格動詞")
		elseif data.trans2 == "unerg" then
			table.insert(data.categories, "荷蘭語非作格動詞")
		elseif data.trans2 == "unacc" then
			table.insert(data.categories, "荷蘭語非賓格動詞")
		else
			error("The \"trans2=\" parameter has an invalid value. Valid are: acc, erg, unerg, unacc.")
		end
	end
	
	if not args["trans"] then
		require("Module:debug").track("nl-verb/no trans")
	end
end

-- Add the unstressed prefix to all the verb forms, or
-- if there is no prefix, add ge- to the past participle
function add_pref(data, pref)
	if pref then
		-- Add prefix before every form
		for key, form in pairs(data.forms) do
			for i, subform in ipairs(form) do
				data.forms[key][i] = pref .. subform
			end
		end
	else
		-- Add ge- prefix before past participle
		if data.forms["past_ptc"] then
			for i, subform in ipairs(data.forms["past_ptc"]) do
				-- Place a diaeresis on the initial vowel of the stem if necessary
				if mw.ustring.find(subform, "^[eiu]") and not mw.ustring.find(subform, "^ij") then
					subform = subform:gsub("^e", "ë"):gsub("^i", "ï"):gsub("^u", "ü")
				end
				
				data.forms["past_ptc"][i] = "ge" .. subform
			end
		end
	end
end

-- Add the separable part to all the verb forms
function add_sep(data, sep)
	if not sep then
		return
	end
	
	-- Add main clause forms
	local mainforms = {}
	
	for key, form in pairs(data.forms) do
		if (key:find("^pres_") or key:find("^past_")) and not key:find("_ptc$") then
			mainforms[key .. "_main"] = mw.clone(form)
		end
	end
	
	for key, form in pairs(mainforms) do
		data.forms[key] = form
	end
	
	-- Add separable part to forms
	for key, form in pairs(data.forms) do
		if key:find("_main$") or key:find("^impr_") then
			-- For main-clause finite forms, add the separable part after the form, separated by a space
			for i, subform in ipairs(data.forms[key]) do
				data.forms[key][i] = data.forms[key][i] .. " " .. sep
			end
		else
			-- For all other forms, add the separable part before the form, with no space
			for i, subform in ipairs(data.forms[key]) do
				-- Add a hyphen after the separable part if it ends with the same vowel
				-- that the main/prefixed verb begins with, for verbs like na-apen
				if mw.ustring.find("aeiou", sep:sub(-1)) and sep:sub(-1) == subform:sub(1, 1) then
					subform = sep .. "-" .. subform
				else
					subform = sep .. subform
				end
				
				data.forms[key][i] = subform
			end
		end
	end
end


--[=[
	*** REGULAR VERBS (mostly) ***
]=]--

local function addform(data, key, form, index)
	if data.forms[key] then
		if index then
			table.insert(data.forms[key], index, form)
		else
			table.insert(data.forms[key], form)
		end
	else
		data.forms[key] = {form}
	end
end

-- Conjugate a weak verb
inflections["weak"] = {
	params = {
		[1] = {required = true},
		[2] = {},
		[3] = {},
		["dt"] = {},
		},
	func = function(args, data)
		table.insert(data.categories, "荷蘭語弱變化動詞")
		data.title = "弱變化"
		
		local stems = {}
		
		stems["pres"] = args[1] or "{{{1}}}"
		stems["pres_e"] = args[2]
		present(data, stems)
		
		local dt = args["dt"] or (stems["pres_e"]:find("[cfhkpqstx]e$") and "t" or "d")
		
		stems["past"] = stems["pres"]:gsub("([^aeiou])i$", "%1ie") .. dt .. "e"
		past(data, stems)
		
		stems["past_ptc"] = args[3] or make_long(stems["pres"]) .. (stems["pres"]:find("[dt]$") and "" or dt)
		data.forms["past_ptc"] = {stems["past_ptc"]}
		
		if stems["past_ptc"]:find("n$") then
			table.insert(data.categories, "有強變化過去分詞的荷蘭語弱變化動詞")
			data.title = data.title .. ",過去分詞為強變化"
		end
		
		-- "zeggen" has an irregular past tense alongside the regular one
		if stems["pres"] == "zeg" then
			past(data, {["past"] = "zei", ["past_e"] = "zeide", ["past_t"] = "zeidt"}, 1)
			table.insert(data.categories, "荷蘭語不規則弱變化動詞")
			data.title = data.title .. ",不規則"
		end
	end
}

-- Conjugate a weak verb with a past tense in -cht
inflections["weak-cht"] = {
	params = {
		[1] = {required = true},
		[2] = {},
		[3] = {required = true},
		},
	func = function(args, data)
		table.insert(data.categories, "Dutch weak verbs (-cht)")
		data.title = "弱變化,過去式以 ''-cht'' 為詞尾"
		
		local stems = {}
		
		stems["pres"] = args[1] or "{{{1}}}"
		stems["pres_e"] = args[2]
		present(data, stems)
		
		stems["past"] = (args[3] or "{{{3}}}") .. "cht"
		past(data, stems)
		
		stems["past_ptc"] = stems["past"]
		data.forms["past_ptc"] = {stems["past_ptc"]}
	end
}

-- Conjugate a strong verb
inflections["strong"] = {
	params = {
		[1] = {required = true},
		[2] = {required = true},
		[3] = {required = true},
		[4] = {},
		[5] = {},
		[6] = {},
		["class"] = {},
		},
	func = function(args, data)
		local class = args["class"]
		table.insert(data.categories, "荷蘭語" .. (class and "" .. class .. "類" or "") .. "強變化動詞")
		data.title = "強變化" .. (class and ",第" .. class .. "類" or "")
		
		local stems = {}
		
		stems["pres"] = args[1] or "{{{1}}}"
		stems["pres_e"] = args[4]
		present(data, stems)
		
		stems["past"] = args[2] or "{{{2}}}"
		stems["past_e"] = args[5]
		stems["past_t"] = args[6]
		past(data, stems)
		
		stems["past_ptc"] = args[3] or "{{{3}}}"
		data.forms["past_ptc"] = {stems["past_ptc"]}
		
		-- If the final consonant of the past participle is not n, then it is a weak past participle.
		if not stems["past_ptc"]:find("n$") then
			table.insert(data.categories, "有弱變化過去分詞的荷蘭語強變化動詞")
			data.title = data.title .. ",過去分詞為弱變化"
		end
		
		-- "houden" and "snijden" have alternative forms without the final -d
		if stems["pres"] == "houd" then
			addform(data, "pres_indc_1sg", "hou", 1)
			addform(data, "impr_sg", "hou", 1)
			table.insert(data.categories, "荷蘭語不規則強變化動詞")
			data.title = data.title .. ", slightly irregular"
		elseif stems["pres"] == "snijd" then
			addform(data, "pres_indc_1sg", "snij", 1)
			addform(data, "impr_sg", "snij", 1)
			table.insert(data.categories, "荷蘭語不規則強變化動詞")
			data.title = data.title .. ", slightly irregular"
		-- If the initial or final consonants of the present stem don't match, then this verb is irregular.
		elseif stems["pres"]:match("^([^aeiouyj]*)") ~= stems["past"]:match("^([^aeiouyj]*)") or stems["pres"]:match("([^aeiouyj]*)$") ~= stems["past"]:match("([^aeiouyj]*)$") then
			table.insert(data.categories, "荷蘭語不規則強變化動詞")
			data.title = data.title .. ",不規則"
		end
	end
}

-- Conjugate an irregular verb
inflections["irregular"] = {
	params = {
		[1] = {required = true},
		},
	func = function(args, data)
		local base = args[1] or "zijn"
		
		if irregular[base] then
			irregular[base](data)
		else
			error("Unknown irregular verb '" .. base .. "'.")
		end
	end
}


--[=[
	*** IRREGULAR VERB TYPES ***
]=]--

irregular["doen"] = function(data)
	table.insert(data.categories, "荷蘭語不規則動詞")
	data.title = "不規則"
	
	present(data, {["pres"] = "doe", ["pres_e"] = "doe"})
	past(data, {["past"] = "deed", ["past_e"] = "dede"})
	data.forms["past_ptc"] = {"daan"}
	
	data.forms["pres_indc_u"] = {"doet"}
	data.forms["pres_indc_3sg"] = {"doet"}
end

irregular["hebben"] = function(data)
	table.insert(data.categories, "荷蘭語不規則弱變化動詞")
	data.title = "弱變化,不規則"
	
	present(data, {["pres"] = "heb", ["pres_e"] = "hebbe"})
	past(data, {["past"] = "had", ["past_e"] = "hadde"})
	data.forms["past_ptc"] = {"had"}
	
	data.forms["pres_indc_u"] = {"hebt", "heeft"}
	data.forms["pres_indc_3sg"] = {"heeft"}
end

irregular["kunnen"] = function(data)
	table.insert(data.categories, "Dutch preterite-present verbs")
	data.title = "preterite-present"
	
	present(data, {["pres"] = "kan", ["pres_e"] = "kunne", ["pres_t"] = "kunt"})
	past(data, {["past"] = "kon", ["past_e"] = "konde", ["past_t"] = "kondt"})
	
	addform(data, "pres_indc_jij", "kan")
	addform(data, "pres_indc_u", "kan")
	data.forms["pres_indc_3sg"] = {"kan"}
	
	data.forms["past_ptc"] = {"kund"}
end

irregular["moeten"] = function(data)
	table.insert(data.categories, "Dutch preterite-present verbs")
	data.title = "preterite-present"
	
	present(data, {["pres"] = "moet"})
	past(data, {["past"] = "moest"})
	data.forms["past_ptc"] = {"moeten"}
end

irregular["mogen"] = function(data)
	table.insert(data.categories, "Dutch preterite-present verbs")
	data.title = "preterite-present"
	
	present(data, {["pres"] = "mag", ["pres_e"] = "moge", ["pres_t"] = "moogt"})
	past(data, {["past"] = "mocht"})
	
	data.forms["pres_indc_jij"] = {"mag"}
	data.forms["pres_indc_u"] = {"mag"}
	data.forms["pres_indc_3sg"] = {"mag"}
	
	data.forms["past_ptc"] = {"mogen"}
end

irregular["weten"] = function(data)
	table.insert(data.categories, "Dutch preterite-present verbs")
	data.title = "preterite-present"
	
	present(data, {["pres"] = "weet", ["pres_e"] = "wete"})
	past(data, {["past"] = "wist"})
	data.forms["past_ptc"] = {"weten"}
end

irregular["willen"] = function(data)
	table.insert(data.categories, "荷蘭語不規則動詞")
	data.title = "不規則"
	
	present(data, {["pres"] = "wil", ["pres_e"] = "wille"})
	past(data, {["past"] = "wilde"})
	past(data, {["past"] = "wou", ["past_e"] = "woude", ["past_t"] = "woudt"})
	data.forms["past_ptc"] = {"wild"}
	
	addform(data, "pres_indc_jij", "wil")
	addform(data, "pres_indc_u", "wil")
	data.forms["pres_indc_3sg"] = {"wil"}
end

irregular["zijn"] = function(data)
	table.insert(data.categories, "荷蘭語不規則動詞")
	table.insert(data.categories, "荷蘭語異幹動詞")
	data.title = "不規則,異幹"
	
	present(data, {["pres"] = "ben", ["pres_e"] = "zij", ["pres_t"] = "zijt"})
	past(data, {["past"] = "was", ["past_e"] = "ware", ["past_t"] = "waart"})
	data.forms["past_ptc"] = {"weest"}
	
	data.forms["pres_indc_jij"] = {"bent"}
	data.forms["pres_indc_u"] = {"bent", "is"}
	data.forms["pres_indc_3sg"] = {"is"}
	addform(data, "impr_sg", "wees", 1)
	addform(data, "impr_pl", "weest", 1)
end

irregular["zullen"] = function(data)
	table.insert(data.categories, "Dutch preterite-present verbs")
	data.title = "preterite-present"
	
	present(data, {["pres"] = "zal", ["pres_e"] = "zulle", ["pres_t"] = "zult"})
	past(data, {["past"] = "zou", ["past_e"] = "zoude", ["past_t"] = "zoudt"})
	
	data.forms["pres_indc_jij"] = {"zult", "zal"}
	data.forms["pres_indc_u"] = {"zult", "zal"}
	data.forms["pres_indc_3sg"] = {"zal"}
end


--[=[
	*** HELPER FUNCTIONS ***
]=]--

-- Create regular present-tense forms
function present(data, stems, index)
	if not stems["pres_e"] then
		stems["pres_e"] = stems["pres"] .. "e"
	end
	
	if not stems["pres_t"] then
		if mw.ustring.find(stems["pres"], "t$") then
			stems["pres_t"] = make_long(stems["pres"])
		else
			stems["pres_t"] = make_long(stems["pres"]) .. "t"
		end
	end
	
	addform(data, "pres_indc_1sg", stems["pres"], index)
	addform(data, "pres_indc_jij", stems["pres_t"], index)
	addform(data, "pres_indc_gij", stems["pres_t"], index)
	addform(data, "pres_indc_u"  , stems["pres_t"], index)
	addform(data, "pres_indc_3sg", stems["pres_t"], index)
	addform(data, "pres_indc_pl" , make_long(stems["pres_e"]) .. "n", index)
	addform(data, "pres_subj_sg" , stems["pres_e"], index)
	
	addform(data, "impr_sg", stems["pres"], index)
	addform(data, "impr_pl", stems["pres_t"], index)
	
	addform(data, "infinitive", make_long(stems["pres_e"]) .. "n", index)
	addform(data, "pres_ptc", make_long(stems["pres_e"]) .. "nd", index)
end


-- Create regular past-tense forms
function past(data, stems, index)
	if not stems["past_e"] then
		if mw.ustring.find(stems["past"], "e$") then
			stems["past_e"] = stems["past"]
		else
			stems["past_e"] = stems["past"] .. "e"
		end
	end
	
	if not stems["past_t"] then
		if mw.ustring.find(stems["past"], "[^eio]e$") or mw.ustring.find(stems["past"], "[të]$") then
			stems["past_t"] = stems["past"]
		else
			stems["past_t"] = stems["past"] .. "t"
		end
	end
	
	addform(data, "past_indc_sg"  , stems["past"], index)
	addform(data, "past_indc_gij" , stems["past_t"], index)
	addform(data, "past_indc_pl"  , stems["past_e"] .. "n", index)
	addform(data, "past_subj_sg"  , stems["past_e"], index)
end


-- A small helper function for those few verbs that have a stem ending in a
-- vowel (like gaan, staan, skiën, echoën). This lengthens the stem-final vowel.
function make_long(form)
	return (form:gsub("([^aeiou])([ao])$", "%1%2%2"):gsub("([^aeiou])i$", "%1ie"))
end


-- Make the table
function make_table(data, hasSep)
	local function show_form(form)
		if not form then
			return "—"
		elseif type(form) ~= "table" then
			error("a non-table value was given in the list of inflected forms.")
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret, m_links.full_link({lang = lang, term = subform}))
		end
		
		return table.concat(ret, ", ")
	end
	
	local function repl(param)
		if param == "lemma" then
			return m_links.full_link({lang = lang, alt = mw.title.getCurrentTitle().text}, "term")
		elseif param == "info" then
			return data.title and " (" .. data.title .. ")" or ""
		else
			return show_form(data.forms[param])
		end
	end
	
	local wikicode = [=[
{| style="border:1px solid #CCCCFF; text-align:center; line-height:125%" class="inflection-table vsSwitcher" data-toggle-category="inflection" cellspacing="1" cellpadding="3"
|- style="background: #CCCCFF;"
! colspan="5" class="vsToggleElement" style="text-align: left" | {{{lemma}}}的變位形式{{{info}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[不定式]]
| style="min-width: 12em;" | {{{infinitive}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[過去式]][[單數]]
| ]=] .. (hasSep and "{{{past_indc_sg_main}}}" or "{{{past_indc_sg}}}") .. [=[

|- class="vsShow" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[過去]][[分詞]]
| {{{past_ptc}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[不定式]]
| colspan="4" | {{{infinitive}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[動名詞]]
| colspan="4" | {{{infinitive}}} ]=] .. require("Module:gender and number").format_list({"n"}) .. (hasSep and [=[

|- class="vsHide" style="background: #E6E6FF;"
|
| colspan="2" style="font-weight: bold;" | [[主句]]
| colspan="2" style="font-weight: bold;" | [[從句]]
|- class="vsHide" style="background: #E6E6FF;"
| 
| style="min-width: 12em; font-weight: bold" | [[現在式]]
| style="min-width: 12em; font-weight: bold" | [[過去式]]
| style="min-width: 12em; font-weight: bold" | [[現在式]]
| style="min-width: 12em; font-weight: bold" | [[過去式]]]=] or [=[

|- class="vsHide" style="background: #E6E6FF;"
|
| style="min-width: 12em; font-weight: bold" | [[現在式]]
| style="min-width: 12em; font-weight: bold" | [[過去式]]
|-]=]) .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[第一人稱]][[單數]]
| ]=] .. (hasSep and "{{{pres_indc_1sg_main}}} || {{{past_indc_sg_main}}} || " or "") .. [=[{{{pres_indc_1sg}}} || {{{past_indc_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[第二人稱]][[單數]](<span lang="nl">[[jij#荷蘭語|jij]]</span>)
| ]=] .. (hasSep and "{{{pres_indc_jij_main}}} || {{{past_indc_sg_main}}} || " or "") .. [=[{{{pres_indc_jij}}} || {{{past_indc_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[第二人稱]][[單數]](<span lang="nl">[[u#荷蘭語|u]]</span>)
| ]=] .. (hasSep and "{{{pres_indc_u_main}}} || {{{past_indc_sg_main}}} || " or "") .. [=[{{{pres_indc_u}}} || {{{past_indc_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[第二人稱]][[單數]](<span lang="nl">[[gij#荷蘭語|gij]]</span>)
| ]=] .. (hasSep and "{{{pres_indc_gij_main}}} || {{{past_indc_gij_main}}} || " or "") .. [=[{{{pres_indc_gij}}} || {{{past_indc_gij}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[第三人稱]][[單數]]
| ]=] .. (hasSep and "{{{pres_indc_3sg_main}}} || {{{past_indc_sg_main}}} || " or "") .. [=[{{{pres_indc_3sg}}} || {{{past_indc_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[複數]]
| ]=] .. (hasSep and "{{{pres_indc_pl_main}}} || {{{past_indc_pl_main}}} || " or "") .. [=[{{{pres_indc_pl}}} || {{{past_indc_pl}}}
|- class="vsHide" style="background: #E6E6FF; height: 0.5em"
|
| colspan="2" |]=] .. (hasSep and [=[ || colspan="2" |]=] or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[虛擬式]][[單數]]<sup>1</sup>
| ]=] .. (hasSep and "{{{pres_subj_sg_main}}} || {{{past_subj_sg_main}}} || " or "") .. [=[{{{pres_subj_sg}}} || {{{past_subj_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[虛擬式]][[複數]]<sup>1</sup>
| ]=] .. (hasSep and "{{{pres_indc_pl_main}}} || {{{past_indc_pl_main}}} || " or "") .. [=[{{{pres_indc_pl}}} || {{{past_indc_pl}}}
|- class="vsHide" style="background: #E6E6FF; height: 0.5em"
|
| colspan="2" |]=] .. (hasSep and [=[ || rowspan="5" colspan="2" |]=] or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[命令式]][[單數]]
| {{{impr_sg}}}
| rowspan="2" style="background: #E6E6FF;" |
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[命令式]][[複數]]<sup>1</sup>
| {{{impr_pl}}}
|- class="vsHide" style="background: #E6E6FF; height: 0.5em"
|
| colspan="2" |
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[分詞]]
| {{{pres_ptc}}} || {{{past_ptc}}}
|- class="vsHide" style="background: #E6E6FF;"
| colspan="5" style="text-align:left; vertical-align:top; font-size: smaller; line-height: 1em" | <sup>1)</sup>古體。
|}]=]
	
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end

function make_bot_list(data, hasSep)
	local ret = ""
	
	if hasSep then
		ret = ret .. "* sep=1\n"
	end
	
	for key, form in pairs(data.forms) do
		if type(form) == "table" then
			for key2, subform in ipairs(form) do
				ret = ret .. "* " .. key .. "_" .. key2 .. "=" .. subform .. "\n"
			end
		else
			ret = ret .. "* " .. key .. "=" .. form .. "\n"
		end
	end
	
	return ret
end

return export