このモジュールについての説明文ページを モジュール:grc-conj/doc に作成できます

local export = {}

local data = require('モジュール:grc-conj/data')
local m_accent = require('モジュール:grc-accent')
local m_dialects = require('モジュール:grc:Dialects')
local m_links = require('モジュール:links')
local lang = require('モジュール:languages').getByCode('grc')

local conjugations = {}

local args = {}
local tense,conjtype -- e.g. pres, pres-con-a respectively
local stem, stem1, stem2, stem3, stem4, pstem, pstem2 -- stem2 is for non-indicative (non-augmented) aorist
local ctable, pctable
local categories = ''

-- declarations of variables that would otherwise need to be global
local out, vowel, dialgroups, q, me, tha, stha, _, code, contractnote, s
local makeconj, swapargs, dialform, dialforms_generic, dialforms_thematic,
	dialforms_thematic_passive, dialforms_contracted, dialforms_aorpass,
	make_table, get_title, link_form, link, make_num_header, make_rows,
	make_voice_header, make_nonfin_forms, make_notes

local contr = {
--					Ê	 E	  É	   Ĵ	Ĥ	Ḥ	 Ô	  O	   Ó	Û	 Ú	  Ŵ	  Ẃ	  Î	   I	Í
--				   'ε' ,'ε' ,'έ' ,'ει','η','ῃ' ,'ο' ,'ο' ,'ό' ,'ου','ού','ω','ώ','οι','οι','οί'
['con-a']		= {'ᾶ' ,'ᾱ' ,'ᾱ́' ,'ᾷ' ,'ᾶ','ᾷ' ,'ῶ' ,'ω' ,'ώ' ,'ῶ' ,'ώ', 'ῶ','ώ','ῷ' ,'ῳ' ,'ῴ'},
['con-eta']		= {'ῆ' ,'η' ,'ή' ,'ῇ' ,'ῆ','ῇ' ,'ῶ' ,'ω' ,'ώ' ,'ῶ' ,'ώ', 'ῶ','ώ','ῷ' ,'ῳ' ,'ῴ'},
['con-e']		= {'εῖ','ει','εί','εῖ','ῆ','ῇ' ,'οῦ','ου','ού','οῦ','ού','ῶ','ώ','οῖ','οι','οί'},
['con-o']		= {'οῦ','ου','ού','οῖ','ῶ','οῖ','οῦ','ου','ού','οῦ','ού','ῶ','ώ','οῖ','οι','οί'},
['con-omega']	= {'ῶ' ,'ω' ,'ώ' ,'ῷ' ,'ῶ','ῷ' ,'ῶ' ,'ω' ,'ώ' ,'ῶ' ,'ῶ' ,'ῶ','ώ','ῷ' ,'ῳ' ,'ῷ'},
['con-e-epiion']	= {'εῖ','ει','εί','εῖ','ῆ' ,'ῇ' ,'εῦ','ευ','εύ','εῦ','εύ','έω','εώ','έοι','εοι','εοί'},
['con-e-nonatt']	= {'εῖ','ει','εί','εῖ','ῆ' ,'ῇ' ,'έο','εο','εό','έου','εού','έω','εώ','έοι','εοι','εοί'},
['con-e-severe']	= {'ῆ' ,'η' ,'ή' ,'εῖ','ῆ' ,'ῇ' ,'έο','εο','εό','έου','εού','έω','εώ','έοι','εοι','εοί'},
['con-e-severe9']	= {'ῆ' ,'η' ,'ή' ,'εῖ','ῆ' ,'ῇ' ,'ίο','ιο','ιό','ίου','ιού','ίω','ιώ','ίοι','ιοι','ιοί'},
['con-e-boi']		= {'εῖ','ει','εί','εῖ','εῖ','εῖ','ίο','ιο','ιό','ίου','ιού','ίω','ιώ','ίοι','ιοι','ιοί'},
['con-e-mono']	= {'εῖ','εῖ','εί','εῖ','ῆ','ῇ','έο','εο','εό','έου','εού','έω','εώ','έοι','εοι','εοί'},
}

local perf_euph = {
{'μ[πβφ]' ,'μμ','μψ','μπτ','μφθ'},
{'γ[κγχ]' ,'γμ','γξ','γκτ','γχθ'},
{'[πβφ]'  ,'μμ','ψ' ,'πτ' ,'φθ'},
{'[ζτδθσ]','σμ','σ' ,'στ' ,'σθ'},
{'[κγχ]'  ,'γμ','ξ' ,'κτ' ,'χθ'},
{'ν'      ,'σμ','νσ','ντ' ,'νθ'}, -- TODO: this is also problematic because νμ > μμ sometimes
{'λ'      ,'λμ','λσ','λτ' ,'λθ'},
{'ρ'      ,'ρμ','ρσ','ρτ' ,'ρθ'},
{'V'      ,'μ' ,'σ' ,'τ'  ,'σθ'},
}

function export.show(frame)
	
	for k,v in pairs(frame:getParent().args) do
		args[k] = mw.text.trim(v)
	end
	
	-- check that the input is not malformed
	if args[2] then args[2] = mw.ustring.toNFD(args[2]) end
	if args[3] then args[3] = mw.ustring.toNFD(args[3]) end
	if args[4] then args[4] = mw.ustring.toNFD(args[4]) end
	if args[5] then args[5] = mw.ustring.toNFD(args[5]) end
	if (not args[1]:match('irreg')) and ((args[2] and args[2] ~= m_accent.strip_tone(args[2])) or
	   (args[3] and args[3] ~= m_accent.strip_tone(args[3])) or
	   (args[4] and args[4] ~= m_accent.strip_tone(args[4])) or
	   (args[5] and args[5] ~= m_accent.strip_tone(args[5]))) then error('Malformed input (contains extra accents)') end
	
	conjtype = args[1]
	if conjtype == 'fut-ln' then conjtype = 'fut-con-e' end
	tense = conjtype:sub(1,(conjtype:find('-') or conjtype:len()+1)-1)
	stem1 = args[2]
	stem2 = args[3] or '' -- augment or passive
	stem3 = args[4] or '' -- passive
	stem4 = args[5] or '' -- augmented passive
	
	if mw.ustring.find(stem1,'˘') then require('モジュール:debug').track('grc-conj/manual-breve') end
	if args['dial1'] then require('モジュール:debug').track('grc-conj/dial1') end
	if args['titleapp'] then require('モジュール:debug').track('grc-conj/titleapp') end
	if args['prefix'] then
		require('モジュール:debug').track('grc-conj/prefix')
		args['prefix'] = mw.ustring.toNFD(args['prefix'])
	end
	
	-- default voices. the argument is named 'form' for obsolete reasons
	if not args.form then
		if tense == 'futp' then
			args.form = 'mp'
		elseif tense == 'fut' and stem2 == '' then
			args.form = 'am'
		elseif tense == 'fut' and stem1 == '' then
			args.form = 'pass'
		elseif tense == 'aor' and stem3 == '' then
			args.form = 'am'
		elseif tense == 'aor' and stem1 == '' then
			args.form = 'pass'
		elseif (tense == 'perf' or tense == 'plup') and stem2 == '' then
			args.form = 'act'
		elseif (tense == 'perf' or tense == 'plup') and stem1 == '' then
			args.form = 'mp'
		else
			args.form = 'full'
		end
	end

	if conjtype:match('con') then
		out = ''
		if conjtype:match('con%-[ae]$') and not args.form:match('con') and (args.dial == 'epi' or args.dial == 'ion' or args.dial == 'att' or not args.dial) then -- eta is too unpredictable
			swapargs(1)
			args.titleapp = args.titleapp1 or '(非縮約型)'
			vowel = conjtype:match('con%-(.*)')
			out = makeconj(tense,stem1 .. (conjtype:match('con%-a') and 'ᾰ' or 'ε'),stem2)
		end
		if not args.form:match('open') then
			swapargs(2)
			if args.dial then
				local dialtitle = args.dial
				local dd = m_dialects.labels[dialtitle]
				if dd then
					dialtitle = dd.link and ('[[w:'..dd.link..'|'..dd.display..']]') or dd.display
				end
				args.titleapp = args.titleapp or '('..dialtitle..', 縮約型)'
			else
				args.titleapp = args.titleapp2 or '(縮約型)'
			end
			out = out .. makeconj(conjtype,stem1,stem2)
		end
		return out
	else
		return makeconj(conjtype,stem1,stem2)
	end
end

function makeconj(conjtype,root,root2)
	if not conjugations[conjtype] then error('No such inflection: '..conjtype) end

	stem = root
	stem2 = root2
	conjugations[conjtype]()
	return make_table()
end

function swapargs(suffix)
	--swaps the args so that functions returning multiple tables can have any form customized
	--This function has undefined behaviour if both <arg> and <arg><suffix> are
	--specified; use e.g. <arg>1 and <arg>2 instead.
	local args_ = args
	args = {}
	for code,value in pairs(args_) do
		args[mw.ustring.gsub(code,'(.+)'..suffix..'$','%1')] = value
	end
end

dialgroups = {
	['ark'] = {ara=true,kyp=true,ark=true},
	['severe'] = {ara=true,kyp=true,ark=true,ele=true,lak=true,her=true,kre=true,les=true}, -- lesbian was omitted from §25 — by mistake?
	['buck9'] = { boi=true,kyp=true,				  lak=true,her=true,kre=true},
	['northwest'] = {pho=true,del=true,lok=true,ele=true},
	['doric'] = {lak=true,her=true,meg=true,krn=true,kor=true,arg=true,rho=true,pam=true,koa=true,thr=true,kre=true},
	['west'] = {pho=true,del=true,lok=true,ele=true,
				lak=true,her=true,meg=true,krn=true,kor=true,arg=true,rho=true,pam=true,koa=true,thr=true,kre=true},
	['nonIA'] = {ara=true,kyp=true,ark=true,
				 les=true,the=true,boi=true,
				 pho=true,del=true,lok=true,ele=true,
				 lak=true,her=true,meg=true,krn=true,kor=true,arg=true,rho=true,pam=true,koa=true,thr=true,kre=true},
}

function dialform(form,suffix,dialect,dialect2)
	if args.dial and (args.dial == dialect or 
					args.dial == dialect2 or 
					(dialgroups[dialect] and dialgroups[dialect][args.dial] ) ) then
		local t = (form:sub(1,1) == 'P') and pctable or ctable
		t[form] = suffix
	end
end

function dialforms_generic(form,word)
	
	if (not args.dial) or args.dial == 'att' then
		return word
	end
	
	-- Epic forms (not in Buck)
	if args.dial == 'epi' then
		word = mw.ustring.gsub(word,'μεθᾰ$','με(σ)θᾰ')
		
		if form:match('.S1S') then
			word = word .. '(μῐ)'
		elseif form:match('.S2S') then
			word = mw.ustring.gsub(word,'ς$','σ(θᾰ)')
		elseif form:match('.S3S') then
			word = word .. '(σῐ)'
		end
	end
	
	-- 102
	if dialgroups['nonIA'][args.dial] then
		word = mw.ustring.gsub(word,'σῐ(ν)','σῐ')
	end
	
	-- 138.1 - data unclear
	
	-- 138.2
	if form:match('..3S') and dialgroups['west'][args.dial] then
		word = mw.ustring.gsub(word,'σῐ','τῐ')
	end
	
	-- 138.3
	if form:match('..1P') and dialgroups['west'][args.dial] then
		word = mw.ustring.gsub(word,'μεν$','μες')
	end
	
	-- 138.4 - can't be automated
	if args.dial == 'boi' or args.dial == 'the' then
		-- this is really 139.2 but it's easier to put here
		word = mw.ustring.gsub(word,'νται$','νθαι')
		word = mw.ustring.gsub(word,'ντο$','νθο')
	end
	
	-- 138.5 - can't be automated

	-- 138.6 (or 8)
	if dialgroups['nonIA'][args.dial] then
		word = mw.ustring.gsub(word,'την$','τᾱν')
		word = mw.ustring.gsub(word,'μην$','μᾱν')
		word = mw.ustring.gsub(word,'σθην$','σθᾱν')
		word = mw.ustring.gsub(word,'μένη$','μένᾱ')

		word = mw.ustring.gsub(word,'Mην$','Mᾱν')
		word = mw.ustring.gsub(word,'Hν$','Hᾱν')
		word = mw.ustring.gsub(word,'Mένη$','Mένᾱ')
	end
	
	-- 139.1
	if args.dial == 'boi' then
		word = mw.ustring.gsub(word,'αι$','η')
		word = mw.ustring.gsub(word,'αι,','η,')
--	elseif args.dial == 'the' then -- this only happened at Larissa
--		word = mw.ustring.gsub(word,'αι$','ει')
--		word = mw.ustring.gsub(word,'αι,','ει,')
	elseif args.dial == 'ara' and form:match('[MP][IS]..') then
		word = mw.ustring.gsub(word,'αι$','οι')
		word = mw.ustring.gsub(word,'αι,','οι,')
	end
	if dialgroups['ark'][args.dial] then
		word = mw.ustring.gsub(word,'ο$','υ')
	end
	
	-- 139.2
	if form:match('[MP]O3P') and (args.dial == 'ion' or args.dial == 'epi') then
		word = mw.ustring.gsub(word,'ντο$','ᾰτο')
	end
	-- ion athematic -ᾰτ-: can't be automated
	-- boi -ᾰτ-: data unclear?
	-- boi/the -θ-: see under 138.4.
	
	-- 140
	if form == 'AC3P' then
		if dialgroups['ark'][args.dial] or (dialgroups['doric'][args.dial] and args.dial ~= 'kre') then
			word = mw.ustring.gsub(word,'ντων$','ντω')
		elseif args.dial == 'boi' then
			word = mw.ustring.gsub(word,'ντων$','νθω')
		elseif args.dial == 'les' or args.dial == 'pam' then
			word = mw.ustring.gsub(word,'ντων$','ντον')
		elseif args.dial == 'late' then
			word = mw.ustring.gsub(word,'ντων$','ντωσᾰν')
		end
	elseif form == 'MC3P' then
		if args.dial == 'kor' or args.dial == 'koa' then
			word = mw.ustring.gsub(word,'ων$','ω')
		elseif args.dial == 'epd' or args.dial == 'lak' then
			-- thematic -οσθω for -εσθων must be dealt with separately. this also apples to ato and ele
			word = mw.ustring.gsub(word,'ων$','ω')
		--not going to bother with corcyrian
		elseif args.dial == 'les' or args.dial == 'pam' then
			word = mw.ustring.gsub(word,'ων$','ον')
		elseif args.dial == 'late' then
			word = mw.ustring.gsub(word,'ων$','ωσᾰν')
		end
		
	end
	
	-- 151: data unclear
	
	-- 154: has to be done manually, as Attic has -ναι and -εναι; also Lesbian -ν and -μεναι
	
	-- 160: data unclear
	
	-- 221: I think it's probably best to fix things at around 400 BC, so CιV and ι=ει, η=αι, ει=η but υ=υ, οι=οι.
	
	-- 60.1
	if args.dial == 'ele' then
		word = mw.ustring.gsub(word,'ς','ρ')
	end
	
	-- 66
	if args.dial == 'pam' then
		word = mw.ustring.gsub(word,'νται$','δαι')
		word = mw.ustring.gsub(word,'ντο$','δο')
		word = mw.ustring.gsub(word,'ντι$','δι')
	end
	
	return word
end

function dialforms_thematic()

	dialform('AO2S','οισ(θᾰ)','epi')
	if conjtype:match('con') then
		--τιμα(ε)μεν(αι) is not apparently attested
	elseif m_accent.circ(stem) ~= m_accent.ult(stem) then
		--verb ends in a long vowel
		dialform('AI','ειν/έμεν(αι)/μεναι','epi')
	elseif m_accent.ult(stem) ~= stem then
		--verb ends in a [short] vowel
		dialform('AI','ειν/έμεν(αι)/μεν(αι)','epi')
	else
		dialform('AI','ειν/έμεν(αι)','epi')
	end

	if args.dial and args.dial ~= 'att' then
		ctable['MI2S'] = 'εαι'
		ctable['MS2S'] = 'ηαι'
		ctable['MC2S'] = 'εο'
	end
	
	dialform('MC2S','ιο','buck9') -- 9

	dialform('AS2D','ειτον','boi','the') -- 14
	dialform('AS3D','ειτον','boi','the')
	dialform('AS2P','ειτε','boi','the')
	dialform('MS2S','είαι','boi','the')
	dialform('MS3S','είται','boi','the')
	dialform('MS2D','εισθον','boi','the')
	dialform('MS3D','εισθον','boi','the')
	dialform('MS2P','εισθε','boi','the')

	dialform('AI2S','ῑς','boi') -- 28
	dialform('AI3S','ῑ','boi')
	dialform('AS2S','ῑς','boi') -- this is a conjecture
	dialform('AS3S','ῑ','boi')
	
	dialform('MC2S','ευ','ion') -- 42.5
	
	dialform('APF','ῶσᾰ','severe','boi') -- 77.3
	dialform('APF','όνσᾰ','kre','arg')
	dialform('APF','όνσᾰ','the','ark')
	dialform('APF','οισᾰ','les')
	
	dialform('AI3P','οντῐ','west') -- 138.4
	dialform('AS3P','ωντῐ','west')
	dialform('AI3P','ονσῐ','ara')
	dialform('AS3P','ωνσῐ','ara')
	dialform('AI3P','ωσῐ','kyp')
	dialform('AS3P','ωσῐ','kyp')
	dialform('AI3P','ονθῐ','boi','the')
	dialform('AS3P','ωνθῐ','boi','the')
	dialform('AI3P','οισῐ','les')
	dialform('AS3P','ῳσῐ','les')

	dialform('MC3P','όσθω','epd','lak') -- 140
	dialform('MC3P','ούσθω','kor')
	dialform('MC3P','όσθων','ato','ele')
	
	dialform('AS3S','η','ark') -- 149

	dialform('AI','ην','les') -- 153
	dialform('AI','ην','ele','lak')
	dialform('AI','εν','ark','del')
	dialform('AI','εν','doric')
	dialform('AI','ειν','krn','rho') -- exceptions to doric -εν
	dialform('AI','έμεν','boi','the') -- 155
end

function dialforms_thematic_passive()
	if args.dial and args.dial ~= 'att' then
		ctable['PI2S'] = 'ησεαι'
		ctable['PS2S'] = 'ησηαι'
		ctable['PC2S'] = 'ησεο'
	end
	
	dialform('PC2S','ησιο','buck9') -- 9

	dialform('PS2S','είαι','boi','the') -- 14
	dialform('PS3S','είται','boi','the')
	dialform('PS2D','εισθον','boi','the')
	dialform('PS3D','εισθον','boi','the')
	dialform('PS2P','εισθε','boi','the')

	dialform('PC2S','ευ','ion') -- 42.5
	
	dialform('PC3P','όσθω','epd','lak') -- 140
	dialform('PC3P','ούσθω','kor')
	dialform('PC3P','όσθων','ato','ele')
end


conjugations['pres'] = function()
	ctable = data.pres
	dialforms_thematic()
end

conjugations['imperf'] = function()
	ctable = data.imperf
end

function dialforms_contracted()
	if args.dial and args.dial ~= 'att' then
		ctable['MI2S'] = 'Êαι'
		ctable['MS2S'] = 'Ĥαι'
		ctable['MC2S'] = 'Êο'
		
		ctable['AO1S'] = 'Îμι'
		ctable['AO2S'] = 'Îς'
		ctable['AO3S'] = 'Î'
		ctable['AO2D'] = 'Îτον'
		ctable['AO3D'] = 'Íτην'
		ctable['AO1P'] = 'Îμεν'
		ctable['AO2P'] = 'Îτε'
		ctable['AO3P'] = 'Îεν'
	end

	dialform('APF','Ŵσᾰ','severe') -- 77.3
	dialform('APF','Ôνσᾰ','kre','arg')
	dialform('APF','Ôνσᾰ','the','ark')
--	dialform('APF','Îσᾰ','les')
	
	dialform('AI3P','Ôντῐ','west') -- 138.4
	dialform('AS3P','Ŵντῐ','west')
	dialform('AI3P','Ôνσῐ','ara')
	dialform('AS3P','Ŵνσῐ','ara')
	dialform('AI3P','Ŵσῐ','kyp')
	dialform('AS3P','Ŵσῐ','kyp')
	dialform('AI3P','Ôνθῐ','boi','the')
	dialform('AS3P','Ŵνθῐ','boi','the')
--	dialform('AI3P','Îσῐ','les')
--	dialform('AS3P','Yσῐ','les')
	
	dialform('MC3P','Óσθω','epd','lak') -- 140
	dialform('MC3P','Úσθω','kor')
	dialform('MC3P','Óσθων','ato','ele')
	
	dialform('AS3S','Ĥ','ark') -- 149

	dialform('AI','Éμεν','boi','the') -- 155
end

conjugations['pres-con-a'] = function()
	ctable = data.pres_contr
	
	dialform('AI','ᾶν/ήμεναι','epi')

	dialforms_contracted()
end

conjugations['imperf-con-a'] = function()
	ctable = data.imperf_contr
end

conjugations['pres-con-e'] = function()
	--The 'two-syllable' rule in Smyth 397 does not seem to be consistent
	--(does η/ηι/οι count?), and it's unclear to what degree it applied to
	--other dialects.
	ctable = data.pres_contr
	
	if args.dial and args.dial ~= 'att' then
	else
		ctable['MI2S'] = 'Ĵ, Ḥ'
	end
	
	dialform('AI','εῖν/ήμεναι/ῆναι','epi')
	dialform('MI2S','εῖαι/έαι','epi')
	dialform('MC2S','εῦ','epi')

	dialforms_contracted()
	
	dialform('MPM','είμενος','northwest','boi')
	dialform('MPF','ειμένᾱ','northwest','boi')
	dialform('MPN','είμενον','northwest','boi')
end

conjugations['imperf-con-e'] = function()
	ctable = data.imperf_contr

	dialform('MI2S','εῖο/έο','epi')
end

conjugations['pres-con-e-mono'] = function()
	ctable = data.pres_contr

	dialforms_contracted()
end

conjugations['imperf-con-e-mono'] = function()
	ctable = data.imperf_contr
end

conjugations['pres-con-o'] = function()
	ctable = data.pres_contr

	dialforms_contracted()
end

conjugations['imperf-con-o'] = function()
	ctable = data.imperf_contr
end

conjugations['pres-con-eta'] = function()
	ctable = data.pres_contr
end

conjugations['imperf-con-eta'] = function()
	ctable = data.imperf_contr
end

conjugations['pres-con-omega'] = function()
	ctable = data.pres_contr
end

conjugations['imperf-con-omega'] = function()
	ctable = data.imperf_contr
end

conjugations['pres-irreg'] = function()
	ctable = {}
	-- no pres-irregs have passive forms so we should be fine
	local i = 2
	for _,mood in ipairs({'I','S','O','C'}) do
		for _,pn in ipairs({'1S','2S','3S','2D','3D','1P','2P','3P'}) do
			args['A'..mood..pn] = args['A'..mood..pn] or args[i]
			i = i + 1
		end
	end
	args['AI'] = args['AI'] or args[34]
	args['APM'] = args['APM'] or args[35]
	args['APF'] = args['APF'] or args[36]
	args['APN'] = args['APN'] or args[37]
end

conjugations['imperf-irreg'] = function()
	ctable = {}
	local i = 2
	for _,pn in ipairs({'1S','2S','3S','2D','3D','1P','2P','3P'}) do
		args['AI'..pn] = args['AI'..pn] or args[i]
		i = i + 1
	end
end

conjugations['pres-ami'] = function()
	ctable = data.pres_ami
	
	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'αῖτον'
		ctable['AO3D'] = 'αίτην'
		ctable['AO1P'] = 'αῖμεν'
		ctable['AO2P'] = 'αῖτε'
		ctable['AO3P'] = 'αῖεν'
	end
	
	dialform('AC2S','η†/ᾰ','epi') --the AC2S is unclear but η is contracted from αε
	dialform('AI','ᾰ́μεν(αι)','epi')
	
	-- subjunctive seems to surprisingly end up just as Attic

	dialform('APM','αις','les') -- 77.3
	dialform('APF','αισᾰ','les')
	dialform('APF','ᾰ́νσᾰ','kre','arg')
	dialform('APF','ᾰ́νσᾰ','the','ark')
	
	dialform('AI3P','ᾰντῐ','west') -- 138.4
	dialform('AS3P','ῶντῐ','west')
	dialform('AI3P','ᾰνσῐ','ara')
	dialform('AS3P','ῶνσῐ','ara')
	dialform('AI3P','ᾱσῐ','kyp')
	dialform('AS3P','ῶσῐ','kyp')
	dialform('AI3P','ᾰνθῐ','boi','the')
	dialform('AS3P','ῶνθῐ','boi','the')
	dialform('AI3P','αισῐ','les')
	dialform('AS3P','ῷσῐ','les')

	dialform('AI1S','ᾱμῐ','nonIA') -- 138.6
	dialform('AI2S','ᾱς','nonIA') -- also -θα?
	dialform('AI3S','ᾱσῐ','nonIA')
	
	dialform('AI','ᾱν','les') -- 154, 155.3
	dialform('AI','ᾰ́μεν','the','boi')
	dialform('AI','ᾰ́μεν','west')
	dialform('AI','ᾰ́μην, ᾰ́μεν','kre')
	dialform('AI','ᾰ́μειν','rho')

	dialform('AC2S','ᾱ','nonIA') -- 160 - apparently smyth says that aeolic has ᾱ
end

conjugations['imperf-ami'] = function()
	ctable = data.imperf_ami
	
	dialform('AI3P','ᾰν','nonIA') -- 138.5
	
	dialform('AI1S','ᾱν','nonIA') -- 138.6
	dialform('AI2S','ᾱς','nonIA')
	dialform('AI3S','ᾱ','nonIA')
end

conjugations['pres-emi'] = function()
	ctable = data.pres_emi

	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'εῖτον'
		ctable['AO3D'] = 'είτην'
		ctable['AO1P'] = 'εῖμεν'
		ctable['AO2P'] = 'εῖτε'
		ctable['AO3P'] = 'εῖεν'
	end
	
	dialform('AS1S','εω','nonIA')
	dialform('AS2S','ηαι','nonIA')
	dialform('AS1P','εωμεν','nonIA')
	dialform('MS1S','εωμαι','nonIA')
	dialform('MS1P','εωμεν','nonIA')
	dialform('MS3P','εωνται','nonIA')
	
	dialform('AS1S','ιω','buck9')
	dialform('AS1P','ιωμεν','buck9')
	dialform('MS1S','ιωμαι','buck9')
	dialform('MS1P','ιωμεν','buck9')
	dialform('MS3P','ιωνται','buck9')

	dialform('MO3S','εῖτο','nonIA')
	dialform('MO2D','εῖσθον','nonIA')
	dialform('MO3D','είσθην','nonIA')
	dialform('MO1P','είμεθᾰ','nonIA')
	dialform('MO2P','εῖσθε','nonIA')
	dialform('MO3P','εῖντο','nonIA')
	
	dialform('AI2S','ησ(θᾰ)','epi')
	dialform('AI3S','ησῐ/εῖ','epi')
	dialform('AI3P','εῖσῐ','epi')
	dialform('AI','έμεν(αι)','epi')
	
	dialform('APF','ῆσᾰ','severe') -- 77.3
	dialform('APF','ένσᾰ','kre','arg')
	dialform('APF','ένσᾰ','the','ark')

	dialform('AI3P','εντῐ','west') -- 138.4
	dialform('AS3P','εωντῐ','west')
	dialform('AI3P','ενσῐ','ara')
	dialform('AS3P','εωνσῐ','ara')
	dialform('AI3P','ησῐ','kyp')
	dialform('AS3P','ιωσῐ','kyp')
	dialform('AI3P','ενθῐ','boi','the')
	dialform('AS3P','ιωνθῐ','boi')
	dialform('AS3P','εωνθῐ','the')
	dialform('AI3P','εισῐ','les')
	dialform('AS3P','εῳσῐ','les')
	
	dialform('AI','ην','les') -- 154, 155.3
	dialform('AI','έμεν','the','boi')
	dialform('AI','έμεν','west')
	dialform('AI','έμην, έμεν','kre')
	dialform('AI','έμειν','rho')
end

conjugations['imperf-emi'] = function()
	ctable = data.imperf_emi
	
	dialform('AI3P','εν','nonIA') -- 138.5
	dialform('AI3P','εᾰν','boi','kyp')

	dialform('AI1S','ην','nonIA') -- 160
	dialform('AI2S','ης','nonIA')
	dialform('AI3S','η','nonIA')
end

conjugations['pres-omi'] = function()
	ctable = data.pres_omi
	
	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'οῖτον'
		ctable['AO3D'] = 'οίτην'
		ctable['AO1P'] = 'οῖμεν'
		ctable['AO2P'] = 'οῖτε'
		ctable['AO3P'] = 'οῖεν'
	end
	
	dialform('AI2S','οῖσ(θᾰ)','epi')
	dialform('AI3S','ωσῐ/οῖ','epi')
	dialform('AI3P','οῦσῐ','epi')
	dialform('AI','όμεν(αι)','epi')

	dialform('APF','ῶσᾰ','severe','boi') -- 77.3
	dialform('APF','όνσᾰ','kre','arg')
	dialform('APF','όνσᾰ','the','ark')
	dialform('APM','οις','les')
	dialform('APF','οισᾰ','les')
	
	dialform('AI3P','οντῐ','west') -- 138.4
	dialform('AS3P','ῶντῐ','west')
	dialform('AI3P','ονσῐ','ara')
	dialform('AS3P','ῶνσῐ','ara')
	dialform('AI3P','ωσῐ','kyp')
	dialform('AS3P','ῶσῐ','kyp')
	dialform('AI3P','ονθῐ','boi','the')
	dialform('AS3P','ῶνθῐ','boi','the')
	dialform('AI3P','οισῐ','les')
	dialform('AS3P','ῳσῐ','les')

	dialform('AI','ων','les') -- 154, 155.3
	dialform('AI','όμεν','the','boi')
	dialform('AI','όμεν','west')
	dialform('AI','όμην, όμεν','kre')
	dialform('AI','όμειν','rho')

--	dialform('AI2S','οις','les') -- also -θα?
end

conjugations['imperf-omi'] = function()
	ctable = data.imperf_omi
	
	dialform('AI3P','ον','nonIA') -- 138.5
	dialform('AI3P','οᾰν','boi','kyp')

	dialform('AI1S','ων','nonIA') -- 160
	dialform('AI2S','ως','nonIA')
	dialform('AI3S','ω','nonIA')
end

conjugations['pres-numi'] = function()
	ctable = data.pres_numi
	
	dialform('APF','νυισᾰ','les') -- 77.3
	dialform('APF','νῠ́νσᾰ','kre','arg')
	dialform('APF','νῠ́νσᾰ','the','ark')
	
	dialform('AI3P','νῠντῐ','west') -- 138.4
	dialform('AS3P','νῠωντῐ','west')
	dialform('AI3P','νῠνσῐ','ara')
	dialform('AS3P','νῠωνσῐ','ara')
	dialform('AI3P','νῡσῐ','kyp')
	dialform('AS3P','νῠωσῐ','kyp')
	dialform('AI3P','νῠνθῐ','boi','the')
	dialform('AS3P','νῠωνθῐ','boi','the')
	dialform('AI3P','νυισῐ','les')
	dialform('AS3P','νῠῳσῐ','les')

	dialform('AI','νῡν','les') -- 154, 155.3
	dialform('AI','νῠ́μεν','the','boi')
	dialform('AI','νῠ́μεν','west')
	dialform('AI','νῠ́μην, νῠ́μεν','kre')
	dialform('AI','νῠ́μειν','rho')
end

conjugations['imperf-numi'] = function()
	ctable = data.imperf_numi
	
	dialform('AI3P','νῠν','nonIA') -- 138.5
	dialform('AI3P','νῠᾰν','boi','kyp')
end

conjugations['fut'] = function()
	ctable = data.pres
	pctable = data.fut_pass
	pstem = stem2
	dialforms_thematic()
	dialforms_thematic_passive()
end

conjugations['fut-con-a'] = function()
	ctable = data.pres_contr
	pctable = data.fut_pass
	pstem = stem2
	
	dialforms_contracted()

	dialform('AI','ᾶν/ήμεναι','epi')
end

conjugations['fut-con-e'] = function()
	ctable = data.pres_contr
	pctable = data.fut_pass
	pstem = stem2
	
	dialforms_contracted()

	dialform('AI','εῖν/ήμεναι/ῆναι','epi')
	dialform('MI2S','εῖαι/έαι','epi')
	dialform('MC2S','εῦ','epi')

	dialform('MPM','είμενος','northwest','boi')
	dialform('MPF','ειμένᾱ','northwest','boi')
	dialform('MPN','είμενον','northwest','boi')
end

conjugations['futp'] = function()
	ctable = data.pres
	dialforms_thematic()
end

function dialforms_aorpass()
	if mw.ustring.sub(pstem,-1) == 'θ' then
		pctable['PC2S'] = 'ητῐ'
	end

	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'εῖτον'
		ctable['AO3D'] = 'είτην'
		ctable['AO1P'] = 'εῖμεν'
		ctable['AO2P'] = 'εῖτε'
		ctable['AO3P'] = 'εῖεν'
	end
	
	dialform('PI3P','ησᾰν/εν','epi')
	dialform('PI','ῆναι/ήμεναι','epi')

	dialform('APF','ῆσᾰ','severe') -- 77.3
	dialform('APF','ένσᾰ','kre','arg')
	dialform('APF','ένσᾰ','the','ark')
	dialform('APF','εισᾰ','les')

	dialform('AS3P','εωντῐ','west') -- 138.4
	dialform('AS3P','εωνσῐ','ara')
	dialform('AS3P','ιωσῐ','kyp')
	dialform('AS3P','ιωνθῐ','boi')
	dialform('AS3P','εωνθῐ','the')
	dialform('AS3P','εῳσῐ','les')

	dialform('PI3P','εν','nonIA') -- 138.5

	dialform('AI','ην','les') -- 154, 155.3
	dialform('AI','ῆμεν','the','boi')
	dialform('AI','ῆμεν','west')
	dialform('AI','ήμην, ῆμεν','kre')
	dialform('AI','ήμειν','rho')
end

conjugations['aor-1'] = function()
	ctable = data.aor_1
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
	
	if args.dial and args.dial ~= 'att' then
		ctable['MS2S'] = 'ηαι'
	end

	dialform('AO2S','αισ(θᾰ)/ειᾰς','epi')
	dialform('AI','αι/ᾰμεν(αι)','epi')
	dialform('MO3P','αίᾰτο','epi')

	dialform('APM','αις','les') -- 77.3
	dialform('APF','αισᾰ','les')
	dialform('APF','ᾰ́νσᾰ','kre','arg')
	dialform('APF','ᾰ́νσᾰ','the','ark')

	dialform('AS3P','ωντῐ','west') -- 138.4
	dialform('AS3P','ωνσῐ','ara')
	dialform('AS3P','ωσῐ','kyp')
	dialform('AS3P','ωνθῐ','boi','the')
	
	dialform('AS2S','εις','les','kre') -- 150 (this is also East Ionic, which we don't have a code for)
	dialform('AS3S','ει','les','kre')
	dialform('AS2D','ετον','les','kre')
	dialform('AS3D','ετον','les','kre')
	dialform('AS1P','ομεν','les','kre')
	dialform('AS2P','ετε','les','kre')
	dialform('AS3P','οισῐ','les')
	dialform('AS3P','οντῐ','kre')
	dialform('MS1S','ομαι','les','kre')
	dialform('MS2S','εαι','les','kre')
	dialform('MS3S','εται','les','kre')
	dialform('MS2D','εσθον','les','kre')
	dialform('MS3D','εσθον','les','kre')
	dialform('MS1P','ομεθᾰ','les','kre')
	dialform('MS2P','εσθε','les','kre')
	dialform('MS3P','ονται','les','kre')

	dialform('AO2S','αις','nonIA') -- 152.4
	dialform('AO3S','αι','nonIA')
	dialform('AO3P','αιεν','nonIA')
	
--	dialform('AI','ειν','the') -- 156 - marked with (Larissa)
	
	dialforms_aorpass()
end

conjugations['aor-2'] = function()
	ctable = data.aor_2
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
	
	-- not used:
	-- local mono = (m_accent.ult(stem2) == stem2)
	
	if args.dial and args.dial ~= 'att' then
		ctable['MI2S'] = 'εο'
		ctable['MS2S'] = 'ηαι'
		ctable['MC2S'] = 'εο' -- assuming from 426c that perispomenon only applies when contracted
	end

	dialform('AO2S','οισ(θᾰ)','epi')
	dialform('AI','εῖν/έμεν(αι)','epi')
	dialform('MO3P','οίᾰτο','epi')
	
	dialform('MI2S','ιο','buck9') -- 9
	dialform('MC2S','ίο','buck9')

	dialform('AS2D','ειτον','boi','the') -- 14
	dialform('AS3D','ειτον','boi','the')
	dialform('AS2P','ειτε','boi','the')
	dialform('MS2S','είαι','boi','the')
	dialform('MS3S','είται','boi','the')
	dialform('MS2D','εισθον','boi','the')
	dialform('MS3D','εισθον','boi','the')
	dialform('MS2P','εισθε','boi','the')

	dialform('AI2S','ῑς','boi') -- 28
	dialform('AI3S','ῑ','boi')
	dialform('AS2S','ῑς','boi') -- this is a conjecture
	dialform('AS3S','ῑ','boi')

	dialform('MI2S','εῦ','ion') -- 42.5
	dialform('MC2S','εῦ','ion')
	
	dialform('APF','ῶσᾰ','severe','boi') -- 77.3
	dialform('APF','όνσᾰ','kre','arg')
	dialform('APF','όνσᾰ','the','ark')
	dialform('APF','οισᾰ','les')

	dialform('AS3P','ωντῐ','west') -- 138.4
	dialform('AS3P','ωνσῐ','ara')
	dialform('AS3P','ωσῐ','kyp')
	dialform('AS3P','ωνθῐ','boi','the')
	dialform('AS3P','ῳσῐ','les')
	

	dialform('MC3P','όσθω','epd','lak') -- 140
	dialform('MC3P','ούσθω','kor')
	dialform('MC3P','όσθων','ato','ele')
	
	dialform('AS3S','η','ark') -- 149

	dialform('AI','ην','les') -- 153
	dialform('AI','ην','ele','lak')
	dialform('AI','εν','ark','del')
	dialform('AI','εν','doric')
	dialform('AI','ειν','krn','rho') -- exceptions to doric -εν
	dialform('AI','έμεν','boi','the') -- 155

	dialforms_aorpass()
end

conjugations['aor-emi'] = function()
	ctable = data.aor_emi
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
	
	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'εῖτον'
		ctable['AO3D'] = 'είτην'
		ctable['AO1P'] = 'εῖμεν'
		ctable['AO2P'] = 'εῖτε'
		ctable['AO3P'] = 'εῖεν'
	end
	
	dialform('AI','έμεν(αι)','epi')
	
	dialform('AS1S','εω','nonIA')
	dialform('AS2S','ηαι','nonIA')
	dialform('AS1P','εωμεν','nonIA')
	dialform('MS1S','εωμαι','nonIA')
	dialform('MS1P','εωμεν','nonIA')
	dialform('MS3P','εωνται','nonIA')
	
	dialform('AS1S','ιω','buck9')
	dialform('AS1P','ιωμεν','buck9')
	dialform('MS1S','ιωμαι','buck9')
	dialform('MS1P','ιωμεν','buck9')
	dialform('MS3P','ιωνται','buck9')

	dialform('MO3S','εῖτο','nonIA')
	dialform('MO2D','εῖσθον','nonIA')
	dialform('MO3D','είσθην','nonIA')
	dialform('MO1P','είμεθᾰ','nonIA')
	dialform('MO2P','εῖσθε','nonIA')
	dialform('MO3P','εῖντο','nonIA')
	
	dialform('APF','ῆσᾰ','severe') -- 77.3
	dialform('APF','ένσᾰ','kre','arg')
	dialform('APF','ένσᾰ','the','ark')

	dialform('AS3P','εωντῐ','west') -- 138.4
	dialform('AS3P','εωνσῐ','ara')
	dialform('AS3P','ιωσῐ','kyp')
	dialform('AS3P','ιωνθῐ','boi')
	dialform('AS3P','εωνθῐ','the')
	dialform('AS3P','εῳσῐ','les')
	
	dialform('AI3P','εν','nonIA') -- 138.5

	dialform('AI','έμεναι','les') -- 154
	dialform('AI','έμεν','the','boi')
	dialform('AI','έμεν','west')
	dialform('AI','έμην, έμεν','kre')
	dialform('AI','έμειν','rho')
end

conjugations['aor-omi'] = function()
	ctable = data.aor_omi
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4

	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'οῖτον'
		ctable['AO3D'] = 'οίτην'
		ctable['AO1P'] = 'οῖμεν'
		ctable['AO2P'] = 'οῖτε'
		ctable['AO3P'] = 'οῖεν'
	end
	
	dialform('AI','όμεν(αι)','epi')

	dialform('APF','ῶσᾰ','severe','boi') -- 77.3
	dialform('APF','όνσᾰ','kre','arg')
	dialform('APF','όνσᾰ','the','ark')
	dialform('APM','οις','les')
	dialform('APF','οισᾰ','les')
	
	dialform('AS3P','ῶντῐ','west') -- 138.4
	dialform('AS3P','ῶνσῐ','ara')
	dialform('AS3P','ῶσῐ','kyp')
	dialform('AS3P','ῶνθῐ','boi','the')
	dialform('AS3P','ῳσῐ','les')

	dialform('AI3P','ον','nonIA') -- 138.5

	dialform('AI','όμεναι','les') -- 154
	dialform('AI','όμεν','the','boi')
	dialform('AI','όμεν','west')
	dialform('AI','όμην, όμεν','kre')
	dialform('AI','όμειν','rho')
end

conjugations['aor-amiw'] = function()
	require('Module:debug').track('grc-conj/aor-amiw')
	ctable = data.aor_amiw
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4

	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'αῖτον'
		ctable['AO3D'] = 'αίτην'
		ctable['AO1P'] = 'αῖμεν'
		ctable['AO2P'] = 'αῖτε'
		ctable['AO3P'] = 'αῖεν'
	end
	
	dialform('APF','ᾰ́νσᾰ','kre','arg') -- 77.3
	dialform('APF','ᾰ́νσᾰ','the','ark')
	dialform('APM','αις','les')
	dialform('APF','αισᾰ','les')
	
	dialform('AS3P','ῶντῐ','west') -- 138.4
	dialform('AS3P','ῶνσῐ','ara')
	dialform('AS3P','ῶσῐ','kyp')
	dialform('AS3P','ῶνθῐ','boi','the')
	dialform('AS3P','ῳσῐ','les')

	dialform('AI3P','ᾰν','nonIA') -- 138.5

	dialform('AI','ᾰ́μεναι','les') -- 154
	dialform('AI','ᾰ́μεν','the','boi')
	dialform('AI','ᾰ́μεν','west')
	dialform('AI','ᾰ́μην, ᾰ́μεν','kre')
	dialform('AI','ᾰ́μειν','rho')
end

conjugations['aor-ami'] = function()
	require('モジュール:debug').track('grc-conj/aor-ami')
	ctable = data.aor_ami
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4

	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'αῖτον'
		ctable['AO3D'] = 'αίτην'
		ctable['AO1P'] = 'αῖμεν'
		ctable['AO2P'] = 'αῖτε'
		ctable['AO3P'] = 'αῖεν'
	end
	
	dialform('AI','ᾰ́μεν(αι)','epi')
end

conjugations['aor-hmi'] = function()
	require('モジュール:debug').track('grc-conj/aor-hmi')
	ctable = data.aor_hmi
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
end

conjugations['aor-wmi'] = function()
	ctable = data.aor_wmi
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
	
	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'οῖτον'
		ctable['AO3D'] = 'οίτην'
		ctable['AO1P'] = 'οῖμεν'
		ctable['AO2P'] = 'οῖτε'
		ctable['AO3P'] = 'οῖεν'
	end

	dialform('AI','ῶμεν/ώμεναι','epi')

	dialform('APF','ῶσᾰ','severe','boi') -- 77.3
	dialform('APF','όνσᾰ','kre','arg')
	dialform('APF','όνσᾰ','the','ark')
	dialform('APM','οις','les')
	dialform('APF','οισᾰ','les')
	
	dialform('AS3P','ῶντῐ','west') -- 138.4
	dialform('AS3P','ῶνσῐ','ara')
	dialform('AS3P','ῶσῐ','kyp')
	dialform('AS3P','ῶνθῐ','boi','the')
	dialform('AS3P','ῳσῐ','les')

	dialform('AI3P','ον','nonIA') -- 138.5

	dialform('AI','ώμεναι','les') -- 154
	dialform('AI','ῶμεν','the','boi')
	dialform('AI','ῶμεν','west')
	dialform('AI','ώμην, ῶμεν','kre')
	dialform('AI','ώμειν','rho')
end

conjugations['aor-numi'] = function()
	ctable = data.aor_numi
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
end

conjugations['aor-hiemi-comp'] = function()
	ctable = data.aor_hiemic
	pctable = data.aor_pass
	pstem = stem3
	pstem2 = stem4
end

conjugations['aor-irreg'] = function()
	ctable = {}
	-- no aor-irregs have passive forms so we should be fine
	local i = 2
	for _,mood in ipairs({'I','S','O','C'}) do
		for _,pn in ipairs({'1S','2S','3S','2D','3D','1P','2P','3P'}) do
			args['A'..mood..pn] = args['A'..mood..pn] or args[i]
			i = i + 1
		end
	end
	args['AI'] = args['AI'] or args[34]
	args['APM'] = args['APM'] or args[35]
	args['APF'] = args['APF'] or args[36]
	args['APN'] = args['APN'] or args[37]
end

conjugations['perf'] = function()
	ctable = data.perf
	pstem = stem2
	
	if mw.ustring.match(m_accent.strip_accent(pstem),'[αεηιουω]$') then
		pstem = pstem .. 'V'
		ctable['MI3P'] = 'νται'
	end

	--active not found in Homer

	dialform('AI3P','ᾰτι, ᾰντῐ','west') -- 138.4, but no clear distinction?
	dialform('AI3P','ᾰσῐ','ark')
	dialform('AI3P','ᾰνθῐ','boi','the')

	dialform('AS3P','ωντῐ','west') -- 138.4
	dialform('AS3P','ωνσῐ','ara')
	dialform('AS3P','ωσῐ','kyp')
	dialform('AS3P','ωνθῐ','boi','the')
	dialform('AS3P','ῳσῐ','les')

	dialform('AI','ην','les') -- 147.2
	dialform('AI','εν','del','kre')
	dialform('AI','ειν','rho','epd')
	
	dialform('APM','ων','aio') -- 147.3
	dialform('APF','οισᾰ','les')
	dialform('APF','ονσᾰ','the')
	dialform('APF','ωσᾰ','boi')
	dialform('APN','ον','aio')
end

conjugations['plup'] = function()
	ctable = data.plup
	pstem = stem2
	
	if mw.ustring.match(m_accent.strip_accent(pstem),'[αεηιουω]$') then
		pstem = pstem .. 'V'
		ctable['MI3P'] = 'ντο'
	end

	dialform('AI3P','εν','nonIA')
end

conjugations['perf-ami'] = function()
	ctable = data.perf_ami

	if args.dial and args.dial ~= 'att' then
		-- this is never mentioned by Buck, but judging from Pharr the optative dual/plural with η is Attic only
		ctable['AO2D'] = 'αῖτον'
		ctable['AO3D'] = 'αίτην'
		ctable['AO1P'] = 'αῖμεν'
		ctable['AO2P'] = 'αῖτε'
		ctable['AO3P'] = 'αῖεν'
	end
	
	dialform('AI','ᾰ́μεν(αι)','epi')
	dialform('APM','ᾰώς','epi')
	dialform('APF','ᾰυῖᾰ','epi') -- pharr and smyth disagree here
	dialform('APN','ᾰός','epi')
end

conjugations['plup-ami'] = function()
	ctable = data.plup_ami
end

conjugations['perf-irreg'] = function()
	ctable = {}
	-- no perf-irregs have passive forms so we should be fine
	local i = 2
	for _,mood in ipairs({'I','S','O','C'}) do
		for _,pn in ipairs({'1S','2S','3S','2D','3D','1P','2P','3P'}) do
			args['A'..mood..pn] = args['A'..mood..pn] or args[i]
			i = i + 1
		end
	end
	args['AI'] = args['AI'] or args[34]
	args['APM'] = args['APM'] or args[35]
	args['APF'] = args['APF'] or args[36]
	args['APN'] = args['APN'] or args[37]
end

conjugations['plup-irreg'] = function()
	ctable = {}
	local i = 2
	for _,pn in ipairs({'1S','2S','3S','2D','3D','1P','2P','3P'}) do
		args['AI'..pn] = args['AI'..pn] or args[i]
		i = i + 1
	end
end

-- Functions for generating the inflection table

local aliases = {
	['pres'] = '現在',
	['imperf'] = '未完了',
	['fut'] = '未来',
	['aor'] = 'アオリスト',
	['perf'] = '完了',
	['plup'] = '過去完了',
	['futp'] = '未来完了',
	['active'] = 'A',
	['middle'] = 'M',
	['passive'] = 'P',
	['middle/<br>passive'] = 'M',
	['I'] = '直説法',
	['S'] = '接続法',
	['O'] = '希求法',
	['C'] = '命令法',
}

local colors = {
	['pres'] = 'c0cfe4',
	['imperf'] = 'c0e4c0',
	['fut'] = 'e4d4c0',
	['aor'] = 'c0cfe4',
	['perf'] = 'c0e4c0',
	['plup'] = 'e4d4c0',
	['futp'] = 'c0cfe4',
}

local moods = {
	['pres'] = {'I','S','O','C'},
	['imperf'] = {'I'},
	['fut'] = {'I','O'},
	['aor'] = {'I','S','O','C'},
	['perf'] = {'I','S','O','C'},
	['plup'] = {'I'},
	['futp'] = {'I','O'},
}

local voices

-- Make the table
function make_table()
	voices = {'active','middle/<br>passive'}
	if args.form:match('act') then
		voices = {'active'}
	elseif args.form:match('mid') then
		voices = {'middle'}
	elseif args.form:match('pass') then
		voices = {'passive'}
	elseif args.form:match('am') then
		voices = {'active','middle'}
	elseif args.form:match('ap') then
		voices = {'active','passive'}
	elseif tense == 'fut' or tense == 'aor' then
		if args.form:match('mp') then
			voices = {'middle','passive'}
		else
			voices = {'active','middle','passive'}
		end
	elseif args.form:match('mp') then
		voices = {'middle/<br>passive'}
	end
	if tense ~= 'fut' and tense ~= 'aor' then
		aliases['passive'] = 'M'
	end
	
	local dialtitle = args.dial
	if dialtitle then
		local dd = m_dialects.labels[dialtitle]
		if dd then
			dialtitle = dd.link and ('[[w:'..dd.link..'|'..dd.display..']]') or dd.display
		end
		dialtitle = '('..dialtitle..')'
	end
	return [=[<div class="NavFrame">
<div class="NavHead">&nbsp; &nbsp;]=] .. aliases[tense] .. ': ' .. table.concat(get_title(), ', ') .. ' ' .. (args['titleapp'] or dialtitle or '') .. [=[</div>
<div class="NavContent">
{| style="background:#F0F0F0;margin:auto;"

|-
! colspan="2" rowspan="1" style="background:#C0C0C0" | 数
! colspan="3" style="background:#C0C0C0" | 単数
! colspan="2" style="background:#C0C0C0" | 双数
! colspan="3" style="background:#C0C0C0" | 複数

]=] .. make_num_header() .. make_rows() .. make_voice_header() .. make_nonfin_forms() .. make_notes() .. [=[

|}</div></div>]=] .. categories
end

function get_title()
	local q = {}
	if conjtype == 'aor-emi' or conjtype == 'aor-omi' or conjtype == 'perf-ami' or conjtype == 'plup-ami' then
		table.insert(q,link_form('AI2D','true'))
	end
	for _,voice in ipairs(voices) do
		table.insert(q,link_form(aliases[voice]..'I1S',true) )
	end
	return q
end

local target = nil

function link_form(form,istitle)
	local t = (form:sub(1,1) == 'P') and pctable or ctable

	-- check that it's a valid voice
	local v = true -- why is lua so STUPID
	for _,voice in ipairs(voices) do
		if aliases[voice] == form:sub(1,1) then v = false end
	end
	if v then return nil end

	-- Get the form
	q = t[form]
	if (args[form] == nil) and (q == nil or q == '') then return nil end
	
	q = dialforms_generic(form,q)

	-- Apply contraction
	if conjtype:match('con') then
		for i,j in ipairs({'Ê','Ē','É','Ĵ','Ĥ','Ḥ','Ô','Ō','Ó','Û','Ú','Ŵ','Ẃ','Î','Ī','Í'}) do
			local contr_vowel = conjtype:match('con%-.+')
			if contr_vowel == 'con-a' and (args.dial == 'boi' or dialgroups['west'][args.dial]) then
				contr_vowel = 'con-eta'
			elseif contr_vowel == 'con-e' then
				if (not args.dial) or args.dial == 'att' then
				elseif args.dial == 'epi' or args.dial == 'ion' then
					contr_vowel = 'con-e-epiion'
				elseif args.dial == 'boi' then
					contr_vowel = 'con-e-boi'
				elseif dialgroups['buck9'][args.dial] then
					contr_vowel = 'con-e-severe9'
				elseif dialgroups['severe'][args.dial] then
					contr_vowel = 'con-e-severe'
				else
					contr_vowel = 'con-e-nonatt'
				end
				
			end
		
			q = mw.ustring.gsub(q,j,contr[contr_vowel][i] )
		end
	end

	-- Get the stem
	local s = (form:sub(1,1) == 'P') and pstem or stem
	if (tense == 'perf' or tense == 'plup') and form:sub(1,1) == 'M' then s = pstem end
	if tense == 'aor' and not form:match('.I..') then
		s = (form:sub(1,1) == 'P') and pstem2 or stem2
	end
	
	if args[form] then
		q = args[form]
		require('モジュール:debug').track('grc-conj/form-override')
		if q == '' then return nil end
	end

	if (tense == 'perf' or tense == 'plup') and mw.ustring.match(q,'[MSTH]') then
		for _,j in pairs(perf_euph) do
			if mw.ustring.match(s,j[1]..'$') then
				s = mw.ustring.gsub(s,j[1]..'$','')
				for k,l in ipairs({'M','S','T','H'}) do
					q = mw.ustring.gsub(q,l,j[k+1])
				end
				break
			end
		end
	end
	
	s = mw.ustring.gsub(s,'V','')

	q = mw.ustring.gsub(q,', ',',<br>')
	
	-- Link the form
	link = function(alt)
		local parenflag = false
		if mw.ustring.sub(alt,1,1) == '(' then
			parenflag = true
		end
		if parenflag then
			alt = mw.ustring.sub(alt,2)
		elseif mw.ustring.sub(alt,1,1) == '*' then
			alt = mw.ustring.sub(alt,2)
			return m_links.full_link({lang=lang, term=target, alt=alt, tr='-'}, nil, false)
		elseif args[form] then
		else
			alt = s..alt
		end
		--accentuate
		if parenflag then
		elseif args.dial == 'les' then
			alt = m_accent.antepenult(alt)
		elseif form == 'APN' or form == 'AI' or (form == 'MI' and tense == 'perf') then
			alt = m_accent.pencirc(alt)
		elseif form == 'AO3S' and mw.ustring.match(alt,'ι$') then
			alt = m_accent.penult(alt)
		elseif args['prefix'] and tense ~= 'pres' and tense ~= 'fut' and (tense ~= 'aor' or form:match('.I..')) then
			alt = args['prefix']..m_accent.antepenult(mw.ustring.sub(alt,1+mw.ustring.len(args['prefix'])))
		else
			alt = m_accent.antepenult(alt)
		end
		
		--deal with parentheses
		if parenflag then
			target = target .. alt
		else
			target = alt
		end
		
		target = mw.ustring.gsub(target,'͜','')
		target = mw.ustring.gsub(target,'σ$','ς')
		target = mw.ustring.gsub(target,'ςθ','σθ')
		return (parenflag and '(' or '') .. m_links.full_link({lang=lang, term=target, alt=alt, tr='-'}, nil, false)
	end
	
	if mw.ustring.match(q, 'με%(σ%)θᾰ$') then
		q = mw.ustring.toNFC(m_accent.antepenult(s .. q))
		me = mw.ustring.gsub(q, '%(σ%)θᾰ', '')
		tha = me .. 'θᾰ'
		stha = me .. 'σθᾰ'
		q = m_links.full_link{lang=lang, term=tha, alt=me, tr='-'} .. '(' .. m_links.full_link{lang=lang, term=stha, alt='σ', tr='-'} .. ')' .. m_links.full_link{lang=lang, term=tha, alt='θᾰ', tr='-'}
	else
		q,_ = mw.ustring.gsub(q,'(%(?[*%-͂̆̄́̀̈̓̔͜ͅΐ-ώϘ-ϡἀ-ῼ]+)',link)
	end

	if istitle then
		q = mw.ustring.match(q,'[^,]+') -- capture up to comma
		q = mw.ustring.gsub(q,' +$','') -- strip final whitespace
	end
	
	return q
end

function make_num_header()
	local s = '|-\n! style="background:#' .. colors[tense] .. '" colspan="2" |\n'
	for _,num in ipairs({'一人称','二人称','三人称','二人称','三人称','一人称','二人称','三人称'}) do
		s = s .. '! style="background:#' .. colors[tense] .. ';width:12.5%" |' .. num .. '\n'
	end
	return s
end

function make_rows()
	local s = ''
	local lmoods = args['indonly'] and {'I'} or moods[tense]
	for _,voice in pairs(voices) do
		s = s .. '|-\n! rowspan="' .. #lmoods .. '" style="background:#' .. colors[tense] .. '" | '..voice..'\n\n'
		for i,mood in ipairs(lmoods) do
			if i ~= 1 then s = s .. '|-\n' end
			s = s .. '! style="height:3em;background:#' .. colors[tense] .. '" | ' .. aliases[mood] .. '\n'
			for _,j in ipairs({'1S','2S','3S','2D','3D','1P','2P','3P'} ) do
				if aliases[voice] == nil then error(voice) end
				code = aliases[voice]..mood..j
				s = s .. '| ' .. (link_form(code) or '&nbsp;') .. '\n'
			end
		end
	end
	contractnote = mw.ustring.match(s,'†')
	return s
end

function make_voice_header()
	-- not used:
	-- local form = args.form
	local s = ''
	if tense == 'imperf' or tense == 'plup' or args['indonly'] then
		return s
	end
	s = '|-\n! style="background:#' .. colors[tense] .. '" colspan="2" |'
	if tense == 'fut' or tense == 'aor' then
		s = s .. '\n! style="background:#' .. colors[tense] .. '" colspan="3" | '
		if voices[1] == 'active' then s = s .. '能動態' end
		s = s .. '\n! style="background:#' .. colors[tense] .. '" colspan="2" | '
		if voices[2] == 'middle' or voices[1] == 'middle' then s = s .. '中動態' end
		s = s .. '\n! style="background:#' .. colors[tense] .. '" colspan="3" | '
		if voices[1] == 'passive' or voices[2] == 'passive' or voices[3] == 'passive' then s = s .. '受動態' end
	else
		s = s .. '\n! style="background:#' .. colors[tense] .. '" colspan="4" | '
		if voices[1] == 'active' then s = s .. '能動態' end
		s = s .. '\n! style="background:#' .. colors[tense] .. '" colspan="4" | '
		if voices[1] == 'middle/<br>passive' or voices[2] == 'middle/<br>passive' then s = s .. '中動態/受動態' end
	end
	s = s .. '\n'
	return s
end

function make_nonfin_forms()
	if tense == 'imperf' or tense == 'plup' or args['indonly'] then
		return ''
	end
	local s = '|-\n! style="background:#' .. colors[tense] .. '" colspan="2" | 不定詞\n'
	local flag = (tense == 'fut' or tense == 'aor')
	s = s .. '| colspan="' .. (flag and 3 or 4) .. '" | ' .. (link_form('AI') or '') .. '\n'
	s = s .. '| colspan="' .. (flag and 2 or 4) .. '" | ' .. (link_form('MI') or '') .. '\n'
	if flag then
		s = s .. '| colspan="3" | ' .. (link_form('PI') or '') .. '\n'
	end
	s = s .. '|-\n! rowspan="3" style="background:#' .. colors[tense] .. '" | 分詞\n'
	for _,gender in ipairs({'m','f','n'}) do
		if gender ~= 'm' then s = s .. '|-\n' end
		s = s .. '! style="background:#' .. colors[tense] .. '" | ' .. gender .. '\n'
		s = s .. '| colspan="' .. (flag and 3 or 4) .. '" | ' .. (link_form('AP'..string.upper(gender) ) or '') .. '\n'
		s = s .. '| colspan="' .. (flag and 2 or 4) .. '" | ' .. (link_form('MP'..string.upper(gender) ) or '') .. '\n'
		if flag then
			s = s .. '| colspan="3" | ' .. (link_form('PP'..string.upper(gender) ) or '') .. '\n'
		end
	end
	return s
end

function make_notes()
	s = args.notes or ''
	if contractnote then
		s = '† 縮約型\n' .. s -- should go first
	end
	if args.dial then
		s = 'Dialects other than Attic are not well attested. Some forms are based on conjecture. Use with caution.\n' .. s
	else
		s = 'このテーブルはアッティカ方言の活用語尾を示す。\n' .. s
	end
	return '|-\n!style="background:#C0C0C0;font-style:italic;"| Notes:\n|style="background:#F5F5F5; text-align:left; font-size:90%;" colspan="13"| <span class="use-with-mention">' .. s .. '</span>\n'
end

return export