Module:grc-conj

Définition, traduction, prononciation, anagramme et synonyme sur le dictionnaire libre Wiktionnaire.

Ce module affiche les conjugaisons en grec ancien. Il est appelé par certains Catégorie:Modèles de conjugaison en grec ancien.


-- Module importé de [[:en:Module:grc-conj]]

local m_accent = require("Module:grc-accent")

local export = {}

local conjugations = {}
-- The tense (and system)
local fulltense = ""
-- Simple tense
local tense = ""

local args = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
  args = frame:getParent().args
  fulltense = args[1] or error("Conjugation type has not been specified. Please pass parameter 1 to the module invocation")
  tense = fulltense:sub(1, (fulltense:find("-") or fulltense:len() + 1) - 1)
  local data = { forms = {}, title = {}, notes = {} }
  if (tense == "pres" or tense == "imperf") and fulltense ~= "pres-irreg" and fulltense ~= "imperf-irreg" then
    conjugations["pres"](data)
  else
    conjugations[fulltense](data)
  end
  local _, contracted = mw.ustring.find(fulltense, "con")
  if fulltense == "fut-ln" then
    contracted = true
  end
  local titleapp = args.titleapp or ""
  if contracted then
    args.titleapp = "(Contracté) " .. titleapp
  end
  local out = ""
  if not (args["cform"] == "con") then
    out = make_table(data)
  end
  if contracted and not (args["cform"] == "uncon") then
    data = { forms = {}, title = {}, notes = {} }
    local vowel = "e"
    if fulltense ~= "fut-ln" then
      vowel = mw.ustring.sub(fulltense, contracted + 2)
    end
    if vowel == "eta" or vowel == "omega" then
      return out
    elseif vowel == "a" then
      args[2] = args[2] .. "α"
    elseif vowel == "e" or vowel == "e-mono" then
      args[2] = args[2] .. "ε"
    elseif vowel == "o" then
      args[2] = args[2] .. "ο"
    end
    if fulltense == "fut-ln" then
      conjugations["fut"](data)
    else
      fulltense = tense
      conjugations["pres"](data)
    end
    args.titleapp = "(Non contracté) " .. titleapp
    out = out .. make_table(data)
  end
  return out
end

local contr = {
  --			   "ε" ,"ε" ,"έ" ,"ει","η","ῃ" ,"ο" ,"ο" ,"ό" ,"ου" ,"ω" ,"ώ" ,"οι" ,"οι" ,"οί"
  ["a"] = { "ᾶ", "ᾱ", "ά", "ᾷ", "ᾶ", "ᾷ", "ῶ", "ω", "ώ", "ῶ", "ῶ", "ώ", "ῷ", "ῳ", "ῴ" },
  ["eta"] = { "ῆ", "η", "ή", "ῇ", "ῆ", "ῇ", "ῶ", "ω", "ώ", "ῶ", "ῶ", "ώ", "ῷ", "ῳ", "ῴ" },
  ["e"] = { "εῖ", "ει", "εί", "εῖ", "ῆ", "ῇ", "οῦ", "ου", "ού", "οῦ", "ῶ", "ώ", "οῖ", "οι", "οί" },
  ["e-mono"] = { "εῖ", "εῖ", "εί", "εῖ", "ῆ", "ῇ", "έο", "εο", "εό", "έου", "έω", "εώ", "έοι", "εοι", "εοί" },
  ["o"] = { "οῦ", "ου", "ού", "οῖ", "ῶ", "οῖ", "οῦ", "ου", "ού", "οῦ", "ῶ", "ώ", "οῖ", "οι", "οί" },
  ["omega"] = { "ῶ", "ω", "ώ", "ῷ", "ῶ", "ῷ", "ῶ", "ω", "ώ", "ῶ", "ῶ", "ώ", "ῷ", "ῳ", "ῷ" },
}

local conjs = require("Module:grc-conj/data")

--[[
	Conjugation functions
--]]

function addforms(data, ctable, stem)
  for code, suffix in pairs(ctable) do
    if args[code] then
      data.forms[code] = args[code]
    else
      for i = 1, #stem, 1 do
        suffix = mw.ustring.gsub(suffix, i, stem[i])
      end
      data.forms[code] = suffix
    end
  end
end

function addforms_futmid(data, ctable, stem)
  for codex, suffix in pairs(ctable) do
    code = "M" .. string.sub(codex, 2)
    if args[code] then
      data.forms[code] = args[code]
    else
      for i = 1, #stem, 1 do
        suffix = mw.ustring.gsub(suffix, i, stem[i])
      end
      data.forms[code] = suffix
    end
  end
end

function addforms_perfmp(data, ctable, euphon, stem)
  for code, suffix in pairs(ctable) do
    if args[code] then
      data.forms[code] = args[code]
    else
      for i = 1, #stem, 1 do
        suffix = mw.ustring.gsub(suffix, i, stem[i])
      end
      suffix = mw.ustring.gsub(suffix, "M", euphon[1])
      suffix = mw.ustring.gsub(suffix, "S", euphon[2])
      suffix = mw.ustring.gsub(suffix, "T", euphon[3])
      suffix = mw.ustring.gsub(suffix, "H", euphon[4])
      data.forms[code] = suffix
    end
  end
end

function addforms_contr(data, ctable, vowel, stem, futmid)
  for code, suffix in pairs(ctable) do
    if futmid and code:sub(1, 1) == "P" then
      code = "M" .. code:sub(2)
    end
    if args[code] then
      data.forms[code] = args[code]
    else
      for i = 1, #stem, 1 do
        suffix = mw.ustring.gsub(suffix, i, stem[i])
      end
      for i, j in ipairs({ "Ê", "E", "É", "Ĵ", "Ĥ", "Ḥ", "Ô", "O", "Ó", "Û", "Ŵ", "Ẃ", "Î", "I", "Í" }) do
        suffix = mw.ustring.gsub(suffix, j, contr[vowel][i])
        data.forms[code] = suffix
      end
    end
  end
end

function addforms_irreg(data, form)
  if form ~= "mp" then
    for i, mood in ipairs({ "I", "S", "O", "C" }) do
      for j, pers in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        data.forms["A" .. mood .. pers] = args[1 + (i - 1) * 8 + j]
      end
    end
    data.forms["AI"] = args[34]
    data.forms["APM"] = args[35]
    data.forms["APF"] = args[36]
    data.forms["APN"] = args[37]
  end
  if form == "am" then
    for i, mood in ipairs({ "I", "S", "O", "C" }) do
      for j, pers in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        data.forms["M" .. mood .. pers] = args[37 + (i - 1) * 8 + j]
      end
    end
    data.forms["MI"] = args[70]
    data.forms["MPM"] = args[71]
    data.forms["MPF"] = args[72]
    data.forms["MPN"] = args[73]
  end
  if form == "mp" then
    for i, mood in ipairs({ "I", "S", "O", "C" }) do
      for j, pers in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        data.forms["P" .. mood .. pers] = args[1 + (i - 1) * 8 + j]
      end
    end
    data.forms["PI"] = args[34]
    data.forms["PPM"] = args[35]
    data.forms["PPF"] = args[36]
    data.forms["PPN"] = args[37]
  end
end

local pres_index = {
  ["pres"] = { conjs.pres_act, conjs.pres_mp },
  ["pres-ami"] = { conjs.pres_ami_act, conjs.pres_ami_mp },
  ["pres-hmi"] = { conjs.pres_hmi_act, conjs.pres_hmi_mp },
  ["pres-emi"] = { conjs.pres_emi_act, conjs.pres_emi_mp },
  ["pres-omi"] = { conjs.pres_omi_act, conjs.pres_omi_mp },
  ["pres-numi"] = { conjs.pres_numi_act, conjs.pres_numi_mp },
  ["pres-irregular"] = { {}, {} },
  ["imperf"] = { conjs.imperf_act, conjs.imperf_mp },
  ["imperf-ami"] = { conjs.imperf_ami_act, conjs.imperf_ami_mp },
  ["imperf-hmi"] = { conjs.imperf_hmi_act, conjs.imperf_hmi_mp },
  ["imperf-emi"] = { conjs.imperf_emi_act, conjs.imperf_emi_mp },
  ["imperf-omi"] = { conjs.imperf_omi_act, conjs.imperf_omi_mp },
  ["imperf-numi"] = { conjs.imperf_numi_act, conjs.imperf_numi_mp },
  ["imperf-irregular"] = { {}, {} },
}

conjugations["pres"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.penult(args[2]) }
  if args["prefix"] then
    -- 426a: accent cannot precede augment
    local root = mw.ustring.sub(stem[2], 1 + mw.ustring.len(args["prefix"]))
    stem[3] = args["prefix"] .. m_accent.penult(root)
  end
  local form = args["form"] or "full"
  _, contracted = mw.ustring.find(fulltense, "con")
  if contracted then
    contracted = mw.ustring.sub(fulltense, contracted + 2)
  end
  present_system = mw.ustring.find(fulltense, "pres")
  if form == "act" or form == "full" then
    if contracted then
      addforms_contr(data, present_system and conjs.pres_contr_act or conjs.imperf_contr_act, contracted, stem, false)
    else
      addforms(data, pres_index[fulltense][1], stem)
    end
    table.insert(data.title, data.forms["AI1S"])
    if args["prefix"] then
      -- 426d: APN retains accent
      local root = mw.ustring.sub(stem[2], 1 + mw.ustring.len(args["prefix"]))
      data.forms["APN"] = args["APN"] or (args["prefix"] .. m_accent.penult(root) .. "ον")
    end
  end
  if form == "mp" or form == "full" then
    if contracted then
      if contracted ~= "e" and j ~= "e-mono" then
        conjs.pres_contr_mp["PI2S"] = "2Ĵ"
      end
      addforms_contr(data, present_system and conjs.pres_contr_mp or conjs.imperf_contr_mp, contracted, stem, false)
    else
      addforms(data, pres_index[fulltense][2], stem)
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["pres-irreg"] = function(data)
  -- εἰμί, εἶμι, ἧμαι
  local form = args["form"]
  addforms_irreg(data, form)
  if form == "act" then
    table.insert(data.title, data.forms["AI1S"])
  elseif form == "mp" then
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["imperf-irreg"] = function(data)
  -- ἦ, ᾖα, ἥμην
  local form = args["form"]
  addforms_irreg(data, form)
  if form == "act" then
    table.insert(data.title, data.forms["AI1S"])
  elseif form == "mp" then
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["fut"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.penult(args[2]) }
  local form = args["form"] or "full"
  local pstem = {}
  if not args[3] then
    form = args["form"] or "am"
  else
    pstem = { mw.ustring.gsub(args[3], "˘", "") .. "ήσ", mw.ustring.gsub(args[3], "˘", "") .. "ησ" }
  end
  if form == "act" or form == "am" or form == "full" then
    addforms(data, conjs.pres_act, stem)
    table.insert(data.title, data.forms["AI1S"])
    if args["prefix"] then
      -- 426d: APN retains accent
      local root = mw.ustring.sub(stem[2], 1 + mw.ustring.len(args["prefix"]))
      data.forms["APN"] = args["APN"] or (args["prefix"] .. m_accent.penult(root) .. "ον")
    end
  end
  if form ~= "act" and form ~= "pass" then
    addforms_futmid(data, conjs.pres_mp, stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.pres_mp, pstem)
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["fut-ln"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", "") }
  local form = args["form"] or "full"
  local pstem = {}
  if not args[3] then
    form = args["form"] or "am"
  else
    pstem = { mw.ustring.gsub(args[3], "˘", "") .. "ήσ", mw.ustring.gsub(args[3], "˘", "") .. "ησ" }
  end
  if form == "act" or form == "am" or form == "full" then
    addforms_contr(data, conjs.pres_contr_act, "e", stem, false)
    table.insert(data.title, data.forms["AI1S"])
  end
  if form ~= "act" and form ~= "pass" then
    addforms_contr(data, conjs.pres_contr_mp, "e", stem, true)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.pres_mp, pstem)
    table.insert(data.title, data.forms["PI1S"])
  end
  data.notes[""] = "Ce modèle d'inflexion comportait originellement un sigma (i.e. *" .. stem[2] .. "έσω), qui a été abandonné très tôt dans l'histoire du grec ancien."
end

conjugations["aor-1"] = function(data)
  local stem = { m_accent.penult(args[2]), m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", ""), m_accent.penult(args[3]), m_accent.circ(args[3]) }
  if args["prefix"] then
    -- 426a: accent cannot precede augment
    local root = mw.ustring.sub(stem[3], 1 + mw.ustring.len(args["prefix"]))
    stem[1] = args["prefix"] .. m_accent.penult(root)
  end
  local form = args["form"] or "full"
  local pstem = {}
  if not args[4] then
    form = args["form"] or "am"
  else
    pstem = { m_accent.ult(args[4]), mw.ustring.gsub(args[4], "˘", ""), mw.ustring.gsub(args[5], "˘", ""), m_accent.ult(args[5]) }
  end
  local mono = (stem[4] == stem[5])
  if form == "act" or form == "am" or form == "full" then
    addforms(data, (mono and conjs.aor_1m_act or conjs.aor_1_act), stem)
    table.insert(data.title, data.forms["AI1S"])
    if args["prefix"] then
      -- 426d: APN retains accent
      local root = mw.ustring.sub(stem[2], 1 + mw.ustring.len(args["prefix"]))
      data.forms["APN"] = args["APN"] or (args["prefix"] .. m_accent.penult(root) .. "ᾰν")
    end
  end
  if form ~= "act" and form ~= "pass" then
    addforms(data, (mono and conjs.aor_1m_mid or conjs.aor_1_mid), stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.aor_pass, pstem)
    if (not args["PC2S"]) and mw.ustring.sub(data.forms["PC2S"], -4, -4) == "θ" then
      data.forms["PC2S"] = pstem[4] .. "ητῐ"
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["aor-2"] = function(data)
  local stem = { m_accent.penult(args[2]), m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", ""), m_accent.penult(args[3]), m_accent.circ(args[3]) }
  if args["prefix"] then
    -- 426a: accent cannot precede augment
    local root = mw.ustring.sub(stem[3], 1 + mw.ustring.len(args["prefix"]))
    stem[1] = args["prefix"] .. m_accent.penult(root)
  end
  local form = args["form"] or "full"
  local pstem = {}
  if not args[4] then
    form = args["form"] or "am"
  else
    pstem = { m_accent.ult(args[4]), mw.ustring.gsub(args[4], "˘", ""), mw.ustring.gsub(args[5], "˘", ""), m_accent.ult(args[5]) }
  end
  local mono = (stem[4] == stem[5])
  if form == "act" or form == "am" or form == "full" then
    addforms(data, (mono and conjs.aor_2m_act or conjs.aor_2_act), stem)
    table.insert(data.title, data.forms["AI1S"])
  end
  if form ~= "act" and form ~= "pass" then
    addforms(data, (mono and conjs.aor_2m_mid or conjs.aor_2_mid), stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.aor_pass, pstem)
    if (not args["PC2S"]) and mw.ustring.sub(data.forms["PC2S"], -4, -4) == "θ" then
      data.forms["PC2S"] = pstem[4] .. "ητῐ"
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["aor-ami"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", "") }
  local form = args["form"] or "full"
  local pstem = {}
  if not args[4] then
    form = args["form"] or "am"
  else
    pstem = { m_accent.ult(args[4]), mw.ustring.gsub(args[4], "˘", ""), mw.ustring.gsub(args[5], "˘", ""), m_accent.ult(args[5]) }
  end
  local mono = (stem[3] == stem[4])
  if form == "act" or form == "am" or form == "full" then
    addforms(data, (mono and conjs.aor_amim_act or conjs.aor_ami_act), stem)
    table.insert(data.title, data.forms["AI1S"])
  end
  if form ~= "act" and form ~= "pass" then
    addforms(data, (mono and conjs.aor_amim_mid or conjs.aor_ami_mid), stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.aor_pass, pstem)
    if (not args["PC2S"]) and mw.ustring.sub(data.forms["PC2S"], -4, -4) == "θ" then
      data.forms["PC2S"] = pstem[4] .. "ητῐ"
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["aor-hmi"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", "") }
  addforms(data, conjs.aor_hmim_mid, stem)
  table.insert(data.title, data.forms["MI1S"])
end

conjugations["aor-emi"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", "") }
  local form = args["form"] or "full"
  local pstem = {}
  if not args[4] then
    form = args["form"] or "am"
  else
    pstem = { m_accent.ult(args[4]), mw.ustring.gsub(args[4], "˘", ""), mw.ustring.gsub(args[5], "˘", ""), m_accent.ult(args[5]) }
  end
  if form == "act" or form == "am" or form == "full" then
    addforms(data, conjs.aor_emi_act, stem)
    table.insert(data.title, data.forms["AI2D"])
  end
  if form ~= "act" and form ~= "pass" then
    addforms(data, conjs.aor_emi_mid, stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.aor_pass, pstem)
    if (not args["PC2S"]) and mw.ustring.sub(data.forms["PC2S"], -4, -4) == "θ" then
      data.forms["PC2S"] = pstem[4] .. "ητῐ"
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["aor-omi"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", "") }
  local form = args["form"] or "full"
  local pstem = {}
  if not args[4] then
    form = args["form"] or "am"
  else
    pstem = { m_accent.ult(args[4]), mw.ustring.gsub(args[4], "˘", ""), mw.ustring.gsub(args[5], "˘", ""), m_accent.ult(args[5]) }
  end
  local mono = (stem[3] == stem[4])
  if form == "act" or form == "am" or form == "full" then
    addforms(data, (mono and conjs.aor_omim_act or conjs.aor_omi_act), stem)
    table.insert(data.title, data.forms["AI2D"])
  end
  if form ~= "act" and form ~= "pass" then
    addforms(data, (mono and conjs.aor_omim_mid or conjs.aor_omi_mid), stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.aor_pass, pstem)
    if (not args["PC2S"]) and mw.ustring.sub(data.forms["PC2S"], -4, -4) == "θ" then
      data.forms["PC2S"] = pstem[4] .. "ητῐ"
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["aor-wmi"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", "") }
  addforms(data, conjs.aor_wmim_act, stem)
  table.insert(data.title, data.forms["AI1S"])
end

conjugations["aor-numi"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), mw.ustring.gsub(args[3], "˘", "") }
  addforms(data, conjs.aor_numim_act, stem)
  table.insert(data.title, data.forms["AI1S"])
end

conjugations["aor-irreg"] = function(data)
  -- εἷτον (ἵημι)
  local form = args["form"]
  addforms_irreg(data, form)
  table.insert(data.title, data.forms["AI2D"])
  table.insert(data.title, data.forms["MI1S"])
end

conjugations["aor-hiemi-comp"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", "") }
  local form = args["form"] or "full"
  local pstem = {}
  if not args[3] then
    form = args["form"] or "am"
  else
    pstem = { m_accent.ult(args[3]), mw.ustring.gsub(args[3], "˘", ""), mw.ustring.gsub(args[4], "˘", ""), m_accent.ult(args[4]) }
  end
  if form == "act" or form == "am" or form == "full" then
    addforms(data, conjs.aor_hiemic_act, stem)
    table.insert(data.title, data.forms["AI2D"])
  end
  if form ~= "act" and form ~= "pass" then
    addforms(data, conjs.aor_hiemic_mid, stem)
    table.insert(data.title, data.forms["MI1S"])
  end
  if form == "pass" or form == "mp" or form == "full" then
    addforms(data, conjs.aor_pass, pstem)
    if (not args["PC2S"]) and mw.ustring.sub(data.forms["PC2S"], -4, -4) == "θ" then
      data.forms["PC2S"] = pstem[4] .. "ητῐ"
    end
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["perf-ami"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", "") }
  addforms(data, conjs.perf_ami_act, stem)
  table.insert(data.title, data.forms["AI2D"])
end

conjugations["perf"] = function(data)
  local stem = { m_accent.penult(args[2]), m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", "") }
  if args["prefix"] then
    -- 426a: accent cannot precede reduplication
    local root = mw.ustring.sub(stem[3], 1 + mw.ustring.len(args["prefix"]))
    stem[1] = args["prefix"] .. m_accent.penult(root)
  end
  local form = args["form"] or "full"
  local pstem = {}
  local ctable
  if not args[3] then
    form = "act"
  else
    local pass = mw.ustring.sub(args[3], 1, -2)
    local final = mw.ustring.sub(args[3], -1, -1)
    if final == "π" or final == "β" or final == "φ" then
      if mw.ustring.sub(args[3], -2, -2) == "μ" then
        ctable = { "μμ", "μψ", "μπτ", "μφθ" }
        pass = mw.ustring.sub(args[3], 1, -3)
      else
        ctable = { "μμ", "ψ", "πτ", "φθ" }
      end
    elseif final == "τ" or final == "δ" or final == "θ" or final == "σ" then
      ctable = { "σμ", "σ", "στ", "σθ" }
    elseif final == "κ" or final == "γ" or final == "χ" then
      if mw.ustring.sub(args[3], -2, -2) == "γ" then
        ctable = { "γμ", "γξ", "γκτ", "γχθ" }
        pass = mw.ustring.sub(args[3], 1, -3)
      else
        ctable = { "γμ", "ξ", "κτ", "χθ" }
      end
    elseif final == "ν" then
      ctable = { "σμ", "νσ", "ντ", "νθ" }
    elseif final == "λ" or final == "ρ" then
      ctable = { "μ", "σ", "τ", "θ" }
      pass = args[3]
    else
      pass = args[3]
      conjs.perf_mp["PI3P"] = "1νται"
      ctable = { "μ", "σ", "τ", "σθ" }
    end
    pstem = { m_accent.penult(pass), m_accent.ult(pass), mw.ustring.gsub(pass, "˘", ""), m_accent.circ(pass) }
    if args["prefix"] then
      -- 426a: accent cannot precede reduplication
      local root = mw.ustring.sub(pstem[3], 1 + mw.ustring.len(args["prefix"]))
      pstem[1] = args["prefix"] .. m_accent.penult(root)
    end
  end
  if form == "act" or form == "full" then
    addforms(data, conjs.perf_act, stem)
    table.insert(data.title, data.forms["AI1S"])
  end
  if form == "mp" or form == "full" then
    addforms_perfmp(data, conjs.perf_mp, ctable, pstem)
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["perf-irreg"] = function(data)
  -- οἶδα
  local form = args["form"]
  addforms_irreg(data, form)
  table.insert(data.title, data.forms["AI1S"])
end

conjugations["plup-ami"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", "") }
  addforms(data, conjs.plup_ami_act, stem)
  table.insert(data.title, data.forms["AI2D"])
end

conjugations["plup"] = function(data)
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", "") }
  local form = args["form"] or "full"
  local pstem = {}
  local ctable
  if not args[3] then
    form = "act"
  else
    args[4] = args[4] or ""
    local pass = mw.ustring.sub(args[3], 1, -2)
    local ppass = mw.ustring.sub(args[4], 1, -2)
    local final = mw.ustring.sub(args[3], -1, -1)
    if final == "π" or final == "β" or final == "φ" then
      if mw.ustring.sub(args[3], -2, -2) == "μ" then
        ctable = { "μμ", "μψ", "μπτ", "μφθ" }
        pass = mw.ustring.sub(args[3], 1, -3)
        ppass = mw.ustring.sub(args[4], 1, -3)
      else
        ctable = { "μμ", "ψ", "πτ", "φθ" }
      end
    elseif final == "τ" or final == "δ" or final == "θ" or final == "σ" then
      ctable = { "σμ", "σ", "στ", "σθ" }
    elseif final == "κ" or final == "γ" or final == "χ" then
      if mw.ustring.sub(args[3], -2, -2) == "γ" then
        ctable = { "γμ", "γξ", "γκτ", "γχθ" }
        pass = mw.ustring.sub(args[3], 1, -3)
        ppass = mw.ustring.sub(args[4], 1, -3)
      else
        ctable = { "γμ", "ξ", "κτ", "χθ" }
      end
    elseif final == "ν" then
      ctable = { "σμ", "νσ", "ντ", "νθ" }
    elseif final == "λ" or final == "ρ" then
      ctable = { "μ", "σ", "τ", "θ" }
      pass = args[3]
      ppass = args[4]
    else
      pass = args[3]
      ppass = args[4]
      conjs.plup_mp["PI3P"] = "2ντο"
      ctable = { "μ", "σ", "τ", "σθ" }
    end
    pstem = { m_accent.ult(pass), m_accent.penult(pass), mw.ustring.gsub(ppass, "˘", "") }
    if args["prefix"] then
      -- 426a: accent cannot precede reduplication
      local root = mw.ustring.sub(mw.ustring.gsub(pass), 1 + mw.ustring.len(args["prefix"]))
      pstem[2] = args["prefix"] .. m_accent.penult(root)
    end
  end
  if form == "act" or form == "full" then
    addforms(data, conjs.plup_act, stem)
    table.insert(data.title, data.forms["AI1S"])
  end
  if form == "mp" or form == "full" then
    addforms_perfmp(data, conjs.plup_mp, ctable, pstem)
    table.insert(data.title, data.forms["PI1S"])
  end
end

conjugations["plup-irreg"] = function(data)
  -- ᾔδη (οἶδα)
  local form = args["form"]
  addforms_irreg(data, form)
  table.insert(data.title, data.forms["AI1S"])
end

conjugations["futp"] = function(data)
  local form = args["form"] or "mp"
  local stem = { m_accent.ult(args[2]), mw.ustring.gsub(args[2], "˘", ""), m_accent.penult(args[2]) }
  if form == "act" or form == "full" then
    addforms(data, conjs.pres_act, stem)
    table.insert(data.title, data.forms["AI1S"])
  end
  if form == "mp" or form == "full" then
    addforms(data, conjs.pres_mp, stem)
    table.insert(data.title, data.forms["PI1S"])
  end
end

local tenses = {
  ["pres"] = "Présent",
  ["imperf"] = "Imparfait",
  ["fut"] = "Futur",
  ["aor"] = "Aoriste",
  ["perf"] = "Parfait",
  ["plup"] = "Plus-que-parfait",
  ["futp"] = "Futur antérieur",
}

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

local moods = {
  ["pres"] = { "indicatif", "subjonctif", "optatif", "impératif" },
  ["imperf"] = { "indicatif" },
  ["fut"] = { "indicatif", "optatif" },
  ["aor"] = { "indicatif", "subjonctif", "optatif", "impératif" },
  ["perf"] = { "indicatif", "subjonctif", "optatif", "impératif" },
  ["plup"] = { "indicatif" },
  ["futp"] = { "indicatif", "optatif" },
  ["indicatif"] = "I",
  ["subjonctif"] = "S",
  ["optatif"] = "O",
  ["impératif"] = "C",
}

-- Functions for generating the inflection table

-- Make the table
function make_table(data)
  return [=[<div class="NavFrame">
<div class="NavHead">&nbsp; &nbsp;]=] .. tenses[tense] .. " : " .. table.concat(data.title, ", ") .. [=[</div>
<div class="NavContent">
{| class="wikitable centre" style="background:#F0F0F0"

|-
! colspan="2" rowspan="1" style="background:#C0C0C0" | nombre
! colspan="3" style="background:#C0C0C0" | singulier
! colspan="2" style="background:#C0C0C0" | duel
! colspan="3" style="background:#C0C0C0" | pluriel

]=] .. make_num_header(data) .. make_rows(data) .. make_voice_header(data) .. make_nonfin_forms(data) .. [=[|-
| colspan="10" | ]=] .. format_notes(data) .. [=[

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

function link_form(data, form)
  local q = data.forms[form]
  if not q then
    return "| \n"
  end
  local s = {}
  for word in mw.ustring.gmatch(q, "[^/]+") do
    -- split the word by "/"
    local link = "[[" .. word .. "#grc|" .. word .. "]]"
    table.insert(s, link .. "<sup>" .. (data.forms[form .. 'N'] or "") .. "</sup>")
  end
  return "| " .. table.concat(s, "/<br>") .. "\n"
end

function make_num_header()
  local s = "|-\n! style=\"background:#" .. colors[tense] .. "\" colspan=\"2\" |\n"
  for _, num in ipairs({ "première", "deuxième", "troisième", "deuxième", "troisième", "première", "deuxième", "troisième" }) do
    s = s .. "! style=\"background:#" .. colors[tense] .. ";width:12.5%\" |" .. num .. "\n"
  end
  return s
end

function make_rows(data)
  local s = ""
  local lmoods = args["indonly"] and { "indicatif" } or moods[tense]
  if data.forms["AI1S"] then
    s = s .. "|-\n! rowspan=\"" .. #lmoods .. "\" style=\"background:#" .. colors[tense] .. "\" | actif\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] .. "\" | " .. mood .. "\n"
      for _, j in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        s = s .. link_form(data, "A" .. moods[mood] .. j)
      end
    end
  end
  if data.forms["MI1S"] then
    s = s .. "|-\n! rowspan=\"" .. #lmoods .. "\" style=\"background:#" .. colors[tense] .. "\" | moyen\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] .. "\" | " .. mood .. "\n"
      for _, j in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        s = s .. link_form(data, "M" .. moods[mood] .. j)
      end
    end
  end
  if data.forms["PI1S"] and tense ~= "fut" and tense ~= "aor" then
    s = s .. "|-\n! rowspan=\"" .. #lmoods .. "\" style=\"background:#" .. colors[tense] .. "\" | moyen/<br>passif\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] .. "\" | " .. mood .. "\n"
      for _, j in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        s = s .. link_form(data, "P" .. moods[mood] .. j)
      end
    end
  end
  if data.forms["PI1S"] and (tense == "fut" or tense == "aor") then
    s = s .. "|-\n! rowspan=\"" .. #lmoods .. "\" style=\"background:#" .. colors[tense] .. "\" | passif\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] .. "\" | " .. mood .. "\n"
      for _, j in ipairs({ "1S", "2S", "3S", "2D", "3D", "1P", "2P", "3P" }) do
        s = s .. link_form(data, "P" .. moods[mood] .. j)
      end
    end
  end
  return s
end

function make_voice_header(data)
  local s = ""
  if tense == "imperf" or tense == "plup" or args["indonly"] then
    return s
  end
  s = "|-\n! style=\"background:#" .. colors[tense] .. "\" colspan=\"2\" |\n"
  if tense == "fut" or tense == "aor" then
    s = s .. "! style=\"background:#" .. colors[tense] .. "\" colspan=\"3\" | " .. (data.forms["AI"] and "actif\n" or "\n")
    s = s .. "! style=\"background:#" .. colors[tense] .. "\" colspan=\"2\" | " .. (data.forms["MI"] and "moyen\n" or "\n")
    s = s .. "! style=\"background:#" .. colors[tense] .. "\" colspan=\"3\" | " .. (data.forms["PI"] and "passif\n" or "\n")
  else
    s = s .. "! style=\"background:#" .. colors[tense] .. "\" colspan=\"4\" | " .. (data.forms["AI"] and "actif\n" or "\n")
    s = s .. "! style=\"background:#" .. colors[tense] .. "\" colspan=\"4\" | " .. (data.forms["PI"] and "moyen/passif\n" or "\n")
  end
  return s
end

function make_nonfin_forms(data)
  if tense == "imperf" or tense == "plup" or args["indonly"] then
    return ""
  end
  local s = "|-\n! style=\"background:#" .. colors[tense] .. "\" colspan=\"2\" | infinitif\n"
  local flag = (tense == "fut" or tense == "aor")
  s = s .. "| colspan=\"" .. (flag and 3 or 4) .. "\" " .. link_form(data, "AI")
  if flag then
    s = s .. "| colspan=\"2\" " .. link_form(data, "MI")
  end
  s = s .. "| colspan=\"" .. (flag and 3 or 4) .. "\" " .. link_form(data, "PI")
  s = s .. "|-\n! rowspan=\"3\" style=\"background:#" .. colors[tense] .. "\" | participe\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(data, "AP" .. string.upper(gender))
    if flag then
      s = s .. "| colspan=\"2\" " .. link_form(data, "MP" .. string.upper(gender))
    end
    s = s .. "| colspan=\"" .. (flag and 3 or 4) .. "\" " .. link_form(data, "PP" .. string.upper(gender))
  end
  return s
end

function format_notes(data)
  s = "Ces tables de conjugaison devraient être considérées comme un guide. Toutes les formes qu'elles contiennent ne sont pas nécessairement attestées, et les formes peuvent varier significativement selon les dialectes.<br />"
  for i, note in pairs(data.notes) do
    s = s .. "<br /><sup>" .. i .. "</sup>" .. note
  end
  return s
end

return export