This module generates pronunciations for {{grc-IPA}}, which is used in Ancient Greek entries.

Use the sandbox module to try things out without causing problems in entries.

The biggest part of the data is contained in the data module.

ἄγριος (ágrios)
 
  • (grc-cla) IPA(key): /á.ɡri.os/
  • (grc-koi1) IPA(key): /ˈa.ɡri.os/
  • (grc-koi2) IPA(key): /ˈa.ɣri.os/
  • (grc-byz1) IPA(key): /ˈa.ɣri.os/
  • (grc-byz2) IPA(key): /ˈa.ɣri.os/

Mark the vowel length of the ambiguous vowels සහ ι by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ἀκούω (akoúō)
 
  • (grc-cla) IPA(key): /a.kǔː.ɔː/
  • (grc-koi1) IPA(key): /aˈku.o/
  • (grc-koi2) IPA(key): /aˈku.o/
  • (grc-byz1) IPA(key): /aˈku.o/
  • (grc-byz2) IPA(key): /aˈku.o/

Mark the vowel length of the ambiguous vowel by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ἄναρθρος (ánarthros)
 
  • (grc-cla) IPA(key): /á.nar.tʰros/
  • (grc-koi1) IPA(key): /ˈa.nar.tʰros/
  • (grc-koi2) IPA(key): /ˈa.nar.θros/
  • (grc-byz1) IPA(key): /ˈa.nar.θros/
  • (grc-byz2) IPA(key): /ˈa.nar.θros/

Mark the vowel length of the ambiguous vowels සහ α by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ἄνθρωπος (ánthrōpos)
 
  • (grc-cla) IPA(key): /án.tʰrɔː.pos/
  • (grc-koi1) IPA(key): /ˈan.tʰro.pos/
  • (grc-koi2) IPA(key): /ˈan.θro.pos/
  • (grc-byz1) IPA(key): /ˈan.θro.pos/
  • (grc-byz2) IPA(key): /ˈan.θro.pos/

Mark the vowel length of the ambiguous vowel by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ᾰ̓́νθρωπος (ánthrōpos)
 
  • (grc-cla) IPA(key): /án.tʰrɔː.pos/
  • (grc-koi1) IPA(key): /ˈan.tʰro.pos/
  • (grc-koi2) IPA(key): /ˈan.θro.pos/
  • (grc-byz1) IPA(key): /ˈan.θro.pos/
  • (grc-byz2) IPA(key): /ˈan.θro.pos/
ἀρχιμανδρῑ́της (arkhimandrī́tēs)
 
  • (grc-koi2) IPA(key): /ar.çi.manˈdri.tis/
  • (grc-byz1) IPA(key): /ar.çi.manˈdri.tis/
  • (grc-byz2) IPA(key): /ar.çi.manˈdri.tis/
Αὖλος (Aûlos)
 
  • (grc-cla) IPA(key): /âu̯.los/
  • (grc-koi1) IPA(key): /ˈaw.los/
  • (grc-koi2) IPA(key): /ˈa.βlos/
  • (grc-byz1) IPA(key): /ˈa.vlos/
  • (grc-byz2) IPA(key): /ˈa.vlos/
Γᾱ́δ (Gā́d)
 
γαῖᾰ (gaîa)
 
  • (grc-cla) IPA(key): /ɡâi̯.a/
  • (grc-koi1) IPA(key): /ˈɡɛ.a/
  • (grc-koi2) IPA(key): /ˈʝɛ.a/
  • (grc-byz1) IPA(key): /ˈʝe.a/
  • (grc-byz2) IPA(key): /ˈʝe.a/
γένος (génos)
 
  • (grc-cla) IPA(key): /ɡé.nos/
  • (grc-koi1) IPA(key): /ˈɡe.nos/
  • (grc-koi2) IPA(key): /ˈʝe.nos/
  • (grc-byz1) IPA(key): /ˈʝe.nos/
  • (grc-byz2) IPA(key): /ˈʝe.nos/
Δῐονῡ́σῐᾰ (Dionū́sia)
 
  • (grc-cla) IPA(key): /di.o.ny̌ː.si.a/
  • (grc-koi1) IPA(key): /di.oˈny.si.a/
  • (grc-koi2) IPA(key): /ði.oˈny.si.a/
  • (grc-byz1) IPA(key): /ði.oˈny.si.a/
  • (grc-byz2) IPA(key): /ði.oˈni.si.a/
ἐγγενής (engenḗs)
 
  • (grc-cla) IPA(key): /eŋ.ɡe.nɛ̌ːs/
  • (grc-koi1) IPA(key): /eŋ.ɡeˈne̝s/
  • (grc-koi2) IPA(key): /eɲ.ɟeˈnis/
  • (grc-byz1) IPA(key): /eɲ.ɟeˈnis/
  • (grc-byz2) IPA(key): /eɲ.ɟeˈnis/
ἔγγονος (éngonos)
 
  • (grc-cla) IPA(key): /éŋ.ɡo.nos/
  • (grc-koi1) IPA(key): /ˈeŋ.ɡo.nos/
  • (grc-koi2) IPA(key): /ˈeŋ.ɡo.nos/
  • (grc-byz1) IPA(key): /ˈeŋ.ɡo.nos/
  • (grc-byz2) IPA(key): /ˈeŋ.ɡo.nos/
ἔγκειμαι (énkeimai)
 
  • (grc-cla) IPA(key): /éŋ.keː.mai̯/
  • (grc-koi1) IPA(key): /ˈeŋ.ki.mɛ/
  • (grc-koi2) IPA(key): /ˈeɲ.ɟi.mɛ/
  • (grc-byz1) IPA(key): /ˈeɲ.ɟi.me/
  • (grc-byz2) IPA(key): /ˈeɲ.ɟi.me/
ἔκγονος (ékgonos)
 
  • (grc-cla) IPA(key): /éɡ.ɡo.nos/
  • (grc-koi1) IPA(key): /ˈeɡ.ɡo.nos/
  • (grc-koi2) IPA(key): /ˈeɡ.ɣo.nos/
  • (grc-byz1) IPA(key): /ˈeɡ.ɣo.nos/
  • (grc-byz2) IPA(key): /ˈeɡ.ɣo.nos/
ἔκδικος (ékdikos)
 
  • (grc-cla) IPA(key): /éɡ.di.kos/
  • (grc-koi1) IPA(key): /ˈeɡ.di.kos/
  • (grc-koi2) IPA(key): /ˈeɡ.ði.kos/
  • (grc-byz1) IPA(key): /ˈeɡ.ði.kos/
  • (grc-byz2) IPA(key): /ˈeɡ.ði.kos/

Mark the vowel length of the ambiguous vowel ι by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ἐκφῠ́ω (ekphúō)
 
  • (grc-cla) IPA(key): /ekʰ.pʰý.ɔː/
  • (grc-koi1) IPA(key): /ekˈpʰy.o/
  • (grc-koi2) IPA(key): /ekˈɸy.o/
  • (grc-byz1) IPA(key): /ekˈfy.o/
  • (grc-byz2) IPA(key): /ekˈfi.o/
ἔμβρυον (émbruon)
 
  • (grc-cla) IPA(key): /ém.bry.on/
  • (grc-koi1) IPA(key): /ˈem.bry.on/
  • (grc-koi2) IPA(key): /ˈem.bry.on/
  • (grc-byz1) IPA(key): /ˈem.bry.on/
  • (grc-byz2) IPA(key): /ˈem.bri.on/

Mark the vowel length of the ambiguous vowel υ by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ἐρετμόν (eretmón)
 
  • (grc-cla) IPA(key): /e.ret.món/
  • (grc-koi1) IPA(key): /e.retˈmon/
  • (grc-koi2) IPA(key): /e.retˈmon/
  • (grc-byz1) IPA(key): /e.retˈmon/
  • (grc-byz2) IPA(key): /e.retˈmon/
ἐρρήθη (errhḗthē)
 
  • (grc-cla) IPA(key): /er̥.r̥ɛ̌ː.tʰɛː/
  • (grc-koi1) IPA(key): /erˈre̝.tʰe̝/
  • (grc-koi2) IPA(key): /erˈri.θi/
  • (grc-byz1) IPA(key): /erˈri.θi/
  • (grc-byz2) IPA(key): /eˈri.θi/
εὔχωμαι (eúkhōmai)
 
  • (grc-cla) IPA(key): /ěu̯.kʰɔː.mai̯/
  • (grc-koi1) IPA(key): /ˈew.kʰo.mɛ/
  • (grc-koi2) IPA(key): /ˈeɸ.xo.mɛ/
  • (grc-byz1) IPA(key): /ˈef.xo.me/
  • (grc-byz2) IPA(key): /ˈef.xo.me/
Ζεύς (Zeús)
 
Ἡρᾰκλέης (Hērakléēs)
 
  • (grc-cla) IPA(key): /hɛː.ra.klé.ɛːs/
  • (grc-koi1) IPA(key): /(h)e̝.raˈkle.e̝s/
  • (grc-koi2) IPA(key): /i.raˈkle.is/
  • (grc-byz1) IPA(key): /i.raˈkle.is/
  • (grc-byz2) IPA(key): /i.raˈkle.is/
ηὗρον (hēûron)
 
  • (grc-cla) IPA(key): /hɛ̂ːu̯.ron/
  • (grc-koi1) IPA(key): /ˈ(h)e̝w.ron/
  • (grc-koi2) IPA(key): /ˈi.βron/
  • (grc-byz1) IPA(key): /ˈi.vron/
  • (grc-byz2) IPA(key): /ˈi.vron/
Θρᾷξ (Thrâix)
 
  • (grc-cla) IPA(key): /tʰrâːi̯ks/
  • (grc-koi1) IPA(key): /tʰraks/
  • (grc-koi2) IPA(key): /θraks/
  • (grc-byz1) IPA(key): /θraks/
  • (grc-byz2) IPA(key): /θraks/
Κιλικίᾱ (Kilikíā)
 
  • (grc-cla) IPA(key): /ki.li.kí.aː/
  • (grc-koi1) IPA(key): /ki.liˈki.a/
  • (grc-koi2) IPA(key): /ci.liˈci.a/
  • (grc-byz1) IPA(key): /ci.liˈci.a/
  • (grc-byz2) IPA(key): /ci.liˈci.a/

Mark the vowel length of the ambiguous vowels ι, ι සහ ί by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

μάχη (mákhē)
 
  • (grc-cla) IPA(key): /má.kʰɛː/
  • (grc-koi1) IPA(key): /ˈma.kʰe̝/
  • (grc-koi2) IPA(key): /ˈma.çi/
  • (grc-byz1) IPA(key): /ˈma.çi/
  • (grc-byz2) IPA(key): /ˈma.çi/

Mark the vowel length of the ambiguous vowel ά by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

ναῦς (naûs)
 
νομίζω (nomízō)
 
  • (grc-cla) IPA(key): /no.míz.dɔː/
  • (grc-koi1) IPA(key): /noˈmi.zo/
  • (grc-koi2) IPA(key): /noˈmi.zo/
  • (grc-byz1) IPA(key): /noˈmi.zo/
  • (grc-byz2) IPA(key): /noˈmi.zo/

Mark the vowel length of the ambiguous vowel ί by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

οἷαι (hoîai)
 
  • (grc-cla) IPA(key): /hôi̯.ai̯/
  • (grc-koi1) IPA(key): /ˈ(h)y.ɛ/
  • (grc-koi2) IPA(key): /ˈy.ɛ/
  • (grc-byz1) IPA(key): /ˈy.e/
  • (grc-byz2) IPA(key): /ˈi.e/
πᾶς (pâs)
 
πατρίς (patrís)
 
  • (grc-cla) IPA(key): /pa.trís/
  • (grc-koi1) IPA(key): /paˈtris/
  • (grc-koi2) IPA(key): /paˈtris/
  • (grc-byz1) IPA(key): /paˈtris/
  • (grc-byz2) IPA(key): /paˈtris/

Mark the vowel length of the ambiguous vowels α සහ ί by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

Πηληϊάδης (Pēlēïádēs)
 
  • (grc-cla) IPA(key): /pɛː.lɛː.i.á.dɛːs/
  • (grc-koi1) IPA(key): /pe̝.le̝.iˈa.de̝s/
  • (grc-koi2) IPA(key): /pi.li.iˈa.ðis/
  • (grc-byz1) IPA(key): /pi.li.iˈa.ðis/
  • (grc-byz2) IPA(key): /pi.li.iˈa.ðis/

Mark the vowel length of the ambiguous vowels ϊ සහ ά by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

πρᾶγμα (prâgma)
 
  • (grc-cla) IPA(key): /prâːŋ.ma/
  • (grc-koi1) IPA(key): /ˈpraɡ.ma/
  • (grc-koi2) IPA(key): /ˈpraɣ.ma/
  • (grc-byz1) IPA(key): /ˈpraɣ.ma/
  • (grc-byz2) IPA(key): /ˈpraɣ.ma/
Σαπφώ (Sapphṓ)
 
  • (grc-cla) IPA(key): /sapʰ.pʰɔ̌ː/
  • (grc-koi1) IPA(key): /sapˈpʰo/
  • (grc-koi2) IPA(key): /sapˈɸo/
  • (grc-byz1) IPA(key): /sapˈfo/
  • (grc-byz2) IPA(key): /sapˈfo/

Mark the vowel length of the ambiguous vowel α by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

σβέννῡμῐ (sbénnūmi)
 
  • (grc-cla) IPA(key): /zbén.nyː.mi/
  • (grc-koi1) IPA(key): /ˈzben.ny.mi/
  • (grc-koi2) IPA(key): /ˈzβen.ny.mi/
  • (grc-byz1) IPA(key): /ˈzven.ny.mi/
  • (grc-byz2) IPA(key): /ˈzve.ni.mi/
σημεῖον (sēmeîon)
 
  • (grc-cla) IPA(key): /sɛː.mêː.on/
  • (grc-koi1) IPA(key): /se̝ˈmi.on/
  • (grc-koi2) IPA(key): /siˈmi.on/
  • (grc-byz1) IPA(key): /siˈmi.on/
  • (grc-byz2) IPA(key): /siˈmi.on/
σμῑκρός (smīkrós)
 
  • (grc-cla) IPA(key): /zmiː.krós/
  • (grc-koi1) IPA(key): /zmiˈkros/
  • (grc-koi2) IPA(key): /zmiˈkros/
  • (grc-byz1) IPA(key): /zmiˈkros/
  • (grc-byz2) IPA(key): /zmiˈkros/
τάττω (táttō)
 
  • (grc-cla) IPA(key): /tát.tɔː/
  • (grc-koi1) IPA(key): /ˈtat.to/
  • (grc-koi2) IPA(key): /ˈtat.to/
  • (grc-byz1) IPA(key): /ˈtat.to/
  • (grc-byz2) IPA(key): /ˈta.to/

Mark the vowel length of the ambiguous vowel ά by adding a macron after it if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

τὴν ᾰ̓οιδήν (tḕn aoidḗn)
 
  • (grc-cla) IPA(key): /tɛ̀ːn a.oi̯.dɛ̌ːn/
  • (grc-koi1) IPA(key): /te̝n a.yˈde̝n/
  • (grc-koi2) IPA(key): /tin a.yˈðin/
  • (grc-byz1) IPA(key): /tin a.yˈðin/
  • (grc-byz2) IPA(key): /tin a.iˈðin/
τμῆμα (tmêma)
 
  • (grc-cla) IPA(key): /tmɛ̂ː.ma/
  • (grc-koi1) IPA(key): /ˈtme̝.ma/
  • (grc-koi2) IPA(key): /ˈtmi.ma/
  • (grc-byz1) IPA(key): /ˈtmi.ma/
  • (grc-byz2) IPA(key): /ˈtmi.ma/
φιλίᾳ (philíāi)
 
  • (grc-cla) IPA(key): /pʰi.lí.aːi̯/
  • (grc-koi1) IPA(key): /pʰiˈli.a/
  • (grc-koi2) IPA(key): /ɸiˈli.a/
  • (grc-byz1) IPA(key): /fiˈli.a/
  • (grc-byz2) IPA(key): /fiˈli.a/

Mark the vowel length of the ambiguous vowels ι සහ ί by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

χάσμα (khásma)
 
  • (grc-cla) IPA(key): /kʰáz.ma/
  • (grc-koi1) IPA(key): /ˈkʰaz.ma/
  • (grc-koi2) IPA(key): /ˈxaz.ma/
  • (grc-byz1) IPA(key): /ˈxaz.ma/
  • (grc-byz2) IPA(key): /ˈxaz.ma/

Mark the vowel length of the ambiguous vowels ά සහ α by adding a macron after each one if it is long, or a breve if it is short. By default, Module:grc-pronunciation assumes it is short if unmarked.
[This message shows only in preview mode.]

χέω (khéō)
 
  • (grc-cla) IPA(key): /kʰé.ɔː/
  • (grc-koi1) IPA(key): /ˈkʰe.o/
  • (grc-koi2) IPA(key): /ˈçe.o/
  • (grc-byz1) IPA(key): /ˈçe.o/
  • (grc-byz2) IPA(key): /ˈçe.o/
ᾠδῇ (ōidêi)
 
  • (grc-cla) IPA(key): /ɔːi̯.dɛ̂ːi̯/
  • (grc-koi1) IPA(key): /oˈde̝/
  • (grc-koi2) IPA(key): /oˈði/
  • (grc-byz1) IPA(key): /oˈði/
  • (grc-byz2) IPA(key): /oˈði/
κέλευσμα (kéleusma)
 
  • (grc-cla) IPA(key): /ké.leu̯z.ma/
  • (grc-koi1) IPA(key): /ˈke.lewz.ma/
  • (grc-koi2) IPA(key): /ˈce.leβz.ma/
  • (grc-byz1) IPA(key): /ˈce.levz.ma/
  • (grc-byz2) IPA(key): /ˈce.levz.ma/

local export = {}

local mark_implied_length = require('Module:grc-accent').mark_implied_length
local strip_accent = require('Module:grc-accent').strip_accent
-- [[Module:grc-utilities]] converts sequences of diacritics to the order required by this module,
-- then replaces combining macrons and breves with spacing ones.
local m_str_utils = require("Module:string utilities")
local m_utils = require("Module:grc-utilities")
local m_general_utils = require("Module:utilities")
local rearrangeDiacritics = m_utils.pronunciationOrder
local m_utils_data = require("Module:grc-utilities/data")
local diacritics = m_utils_data.diacritics
local m_data = mw.loadData("Module:grc-pronunciation/data")
local m_IPA = require("Module:IPA")
local m_a = require("Module:accent qualifier")
local lang = require("Module:languages").getByCode("grc")
local sc = require("Module:scripts").getByCode("Polyt")

local full_link = m_utils.link
local tag_text = m_utils.tag

local periods = {'cla', 'koi1', 'koi2', 'byz1', 'byz2'}
local inlinePeriods = {'cla', 'koi2', 'byz2'}

local title = mw.title.getCurrentTitle()
local pagename = title.text
local namespace = title.nsText

local rsplit = m_str_utils.split
local rfind = m_str_utils.find
local usub = m_str_utils.sub
local rmatch = m_str_utils.match
local rsubn = m_str_utils.gsub
local toNFD = mw.ustring.toNFD
local ulen = m_str_utils.len
local ulower = m_str_utils.lower
local U = m_str_utils.char
local function fetch(s, i)
	--[==[
	because we fetch a single character at a time so often
	out of bounds fetch gives ''
	]==]
	i = tonumber(i)
	
	if type(i) ~= "number" then
		error("fetch requires a number or a string equivalent to a number as its second argument.")
	end
	
	if i == 0 then
		return ""
	end
	
	local n = 0
	for character in string.gmatch(s, "[\1-\127\194-\244][\128-\191]*") do
		n = n + 1
		if n == i then
			return character
		end
	end
	
	return ""
end

--Combining diacritics are tricky.
local tie = U(0x35C)				-- tie bar
local nonsyllabic = U(0x32F)		-- combining inverted breve below
local high = U(0x341)				-- combining acute tone mark
local low = U(0x340)				-- combining grave tone mark
local rising = U(0x30C)				-- combining caron
local falling = diacritics.Latin_circum	-- combining circumflex
local midHigh = U(0x1DC4)			-- mid–high pitch
local midLow = U(0x1DC6)			-- mid–low pitch
local highMid = U(0x1DC7)			-- high–mid pitch
local voiceless = U(0x325)			-- combining ring below
local aspirated = 'ʰ'
local macron = '¯'
local breve = '˘'

local function is(text, X)
	if not text or not X then
		return false
	end
	pattern = m_data.chars[X] or error('No data for "' .. X .. '".', 2)
	if X == "frontDiphth" or X == "Greekdiacritic" then
		pattern = "^" .. pattern .. "$"
	else
		pattern = "^[" .. pattern .. "]$"
	end
	return rfind(text, pattern)
end

local env_functions = {
	preFront = function(term, index)
		local letter1, letter2 = fetch(term, index + 1), fetch(term, index + 2)
		return is(strip_accent(letter1), "frontVowel") or (is(strip_accent(letter1 .. letter2), "frontDiphth") and not is(letter2, "iDiaer"))
	end,
	isIDiphth = function(term, index)
		local letter = fetch(term, index + 1)
		return strip_accent(letter) == 'ι' and not m_data[letter].diaer
	end,
	isUDiphth = function(term, index)
		local letter = fetch(term, index + 1)
		return strip_accent(letter) == 'υ' and not m_data[letter].diaer
	end,
	hasMacronBreve = function(term, index)
		return fetch(term, index + 1) == macron or fetch(term, index + 1) == breve
	end,
}

local function decode(condition, x, term)
	--[==[
		"If" and "and" statements.
		Note that we're finding the last operator first, 
		which means that the first will get ultimately get decided first.
		If + ("and") or / ("or") is found, the function is called again,
		until if-statements are found.
		In if-statements:
		* A number represents the character under consideration:
			 -1 is the previous character, 0 is the current, and 1 is the next.
		* Equals sign (=) checks to see if the character under consideration
			is equal to a character.
		* Period (.) plus a word sends the module to the corresponding entry
			in the letter's data table.
		* Tilde (~) calls a function on the character under consideration,
			if the function exists.
	]==]
	if rfind(condition, '[+/]') then
		-- Find slash or plus sign preceded by something else, and followed by anything
		-- (including another sequence of slash or plus sign and something else).
		local subcondition1, sep, subcondition2 = rmatch(condition, "^([^/+]-)([/+])(.*)$")
		if not (subcondition1 or subcondition2) then
			error('Condition "' .. tostring(condition) .. '" is improperly formed')
		end
		
		if sep == '/' then		-- logical operator: or
			return decode(subcondition1, x, term) or decode(subcondition2, x, term)
		elseif sep == '+' then	-- logical operator: and
			return decode(subcondition1, x, term) and decode(subcondition2, x, term)
		end
	elseif rfind(condition, '=') then				-- check character identity
		local offset, char = unpack(rsplit(condition, "="))
		if namespace == "Module" or namespace == "Template" then
			mw.log(term, offset, char, x + offset, fetch(term, x + offset), char == fetch(term, x + offset) )
		end
		return char == fetch(term, x + offset) -- out of bounds fetch gives ''
	elseif rfind(condition, '%.') then				-- check character quality
		local offset, quality = unpack(rsplit(condition, "%."))
		local character = fetch(term, x + offset)
		return m_data[character] and m_data[character][quality] or false
	elseif rfind(condition, '~') then				-- check character(s) using function
		local offset, func = unpack(rsplit(condition, "~"))
		return env_functions[func] and env_functions[func](term, x + offset) or false
	end
end

local function check(p, x, term)
	if type(p) == 'string' or type(p) == 'number' then
		return p
	elseif type(p) == 'table' then   --This table is sequential, with a variable number of entries.
		for _, possP in ipairs(p) do
			if type(possP) == 'string' or type(possP) == 'number' then
				return possP
			elseif type(possP) == 'table' then    --This table is paired, with two values: a condition and a result.
				rawCondition, rawResult = possP[1], possP[2]
				if decode(rawCondition, x, term) then
					return (type(rawResult) == 'string') and rawResult or check(rawResult, x, term)
				end	
			end
		end
	else
		error('"p" is of unrecongized type ' .. type(p))
	end
end

local function convert_term(term, periodstart)
	if not term then error('The variable "term" in the function "convert_term" is nil.') end
	local IPAs = {}
	local start
	local outPeriods = {}
	if periodstart and periodstart ~= "" then
		start = false
	else
		start = true
	end
	for _, period in ipairs(periods) do 
		if period == periodstart then
			start = true
		end
		if start then
			IPAs[period] = {}
			table.insert(outPeriods, period)
		end
	end
	local length, x, advance, letter, p = ulen(term), 1, 0, '', nil
	while x <= length do
		letter = fetch(term, x)
		local data = m_data[letter]
		if not data then		-- no data found
			-- explicit pass
		else
			-- check to see if a multicharacter search is warranted
			advance = data.pre and check(data.pre, x, term) or 0
			p = (advance ~= 0) and m_data[usub(term, x, x + advance)].p or data.p
			for _, period in ipairs(outPeriods) do
				table.insert(IPAs[period], check(p[period], x, term))
			end
			x = x + advance
		end
		x = x + 1
	end
	
	--Concatenate the IPAs
	for _, period in ipairs(outPeriods) do
		IPAs[period] = { IPA = table.concat(IPAs[period], '')}
	end
	
	return IPAs, outPeriods
end

local function find_syllable_break(word, nVowel, wordEnd)
	if not word then error('The variable "word" in the function "find_syllable_break" is nil.') end
	if wordEnd then
		return ulen(word)
	elseif is(fetch(word, nVowel - 1), "liquid") then
		if is(fetch(word, nVowel - 2), "obst") then
			return nVowel - 3
		elseif fetch(word, nVowel - 2) == aspirated and is(fetch(word, nVowel - 3), "obst") then
			return nVowel - 4
		else
			return nVowel - 2
		end
	elseif is(fetch(word, nVowel - 1), "cons") then
		return nVowel - 2
	elseif fetch(word, nVowel - 1) == aspirated and is(fetch(word, nVowel - 2), "obst") then
		return nVowel - 3
	elseif fetch(word, nVowel - 1) == voiceless and fetch(word, nVowel - 2) == 'r' then
		return nVowel - 3
	else
		return nVowel - 1
	end
end

local function syllabify_word(word)
	local syllables = {}
	--[[	cVowel means "current vowel", nVowel "next vowel",
			sBreak "syllable break".							]]--
	local cVowel, nVowel, sBreak, stress, wordEnd, searching
	while word ~= '' do
		cVowel, nVowel, sBreak, stress = false, false, false, false
		
		--First thing is to find the first vowel.
		searching = 1
		cVowelFound = false
		while not cVowel do
			letter = fetch(word, searching)
			local nextLetter = fetch(word, searching + 1)
			if cVowelFound then
				if (is(letter, "vowel") and nextLetter ~= nonsyllabic) or is(letter, "cons") or letter == '' or letter == 'ˈ' then
					cVowel = searching - 1
				elseif is(letter, "diacritic") then
					searching = searching + 1
				elseif letter == tie then
					cVowelFound = false
					searching = searching + 1
				else
					searching = searching + 1
				end
			else
				if is(letter, "vowel") then
					cVowelFound = true
				elseif letter == 'ˈ' then
					stress = true
				end
				searching = searching + 1
			end
		end
	
		--Next we try and find the next vowel or the end.
		searching = cVowel + 1
		while (not nVowel) and (not wordEnd) do
			letter = fetch(word, searching)
			if is(letter, "vowel") or letter == 'ˈ' then
				nVowel = searching
			elseif letter == '' then
				wordEnd = true
			else
				searching = searching + 1
			end
		end
		
		--Finally we find the syllable break point.
		sBreak = find_syllable_break(word, nVowel, wordEnd)
		
		--Pull everything up to and including the syllable Break.
		local syllable = usub(word, 1, sBreak)
		
		--If there is a stress accent, then we need to move it to the 
		--beginning of the syllable, unless it is a monosyllabic word,
		--in which case we remove it altogether.
		if stress then
			if next(syllables) or syllable ~= word then
				syllable = 'ˈ' .. rsubn(syllable, 'ˈ', '')
			else 
				syllable = rsubn(syllable, 'ˈ', '')
			end
			stress = false
		end
		table.insert(syllables, syllable)
		word = usub(word, sBreak + 1)
	end
	
	local out = nil
	
	if #syllables > 0 then
		out = table.concat(syllables, '.')
		out = rsubn(out, '%.ˈ', 'ˈ')
	end
	return out
end

local function syllabify(IPAs, periods)
	--Syllabify
	local word_ipa = ''
	local ipa = {}
	for _, period in ipairs(periods) do
		ipa = {}
		for _, word in ipairs(rsplit(IPAs[period].IPA, ' ')) do
			word_ipa = syllabify_word(word)
			if word_ipa then
				table.insert(ipa, word_ipa)
			end
		end
		IPAs[period].IPA = table.concat(ipa, ' ')
	end
	return IPAs
end

local function make_ambig_note(ambig, ambig_letter_list)
	-- The table ambig is filled with all the ambiguous vowels that have been found in the term.
	local ambig_note = ''
	if ambig and #ambig > 0 then
		local agr = (#ambig > 1) and { 's ', 'each one' } or { ' ', 'it' }
			
		ambig_note = '\n<p class="previewonly">Mark the vowel length of the ambiguous vowel' .. agr[1]
			.. mw.text.listToText(ambig) .. ' by adding a macron after ' .. agr[2]
			.. ' if it is long, or a breve if it is short. By default, [[Module:grc-pronunciation]] assumes it is short if unmarked.'
			.. '<br/><small>[This message shows only in preview mode.]</small>'
			.. m_general_utils.format_categories(
				{ 'Ancient Greek terms with incomplete pronunciation' }, lang)
			..'</p>\n'
	end
	return ambig_note
end

local function make_table(IPAs, ambig, periods, ambig_letter_list)
	--Final format
	local inlineProns = {}
	local listOfProns = {}
	local fullProns = {}
	local periods2 = {}
	
	for _, period in ipairs(periods) do
		table.insert(fullProns, '* ' .. m_a.format_qualifiers(lang, {"grc-" .. period}) .. ' ' ..
			m_IPA.format_IPA_full {
				lang = lang,
				items = {{pron = '/' .. IPAs[period].IPA .. '/'}},
			})
		periods2[period] = true 
	end
	
	for _, period in ipairs(inlinePeriods) do
		if periods2[period] then
			local pron = '/' .. IPAs[period].IPA .. '/'
			table.insert(inlineProns, {pron = pron})
			table.insert(listOfProns, pron)
		end
	end
	
	local inlineIPAlength = math.floor( math.max( ulen("IPA(key): " .. table.concat(listOfProns, ' → ') or "") * 0.68, ulen("(15th AD Constantinopolitan) IPA(key): /" .. IPAs.byz2.IPA .. "/") * 0.68 ) )
	
	local inline = '\n<div class="vsShow" style="display:none">\n* ' .. m_IPA.format_IPA_full {
		lang = lang,
		items = inlineProns,
		separator = " → ",
	} .. "</div>"
	
	local full = '\n<div class="vsHide">\n' .. table.concat(fullProns, '\n') .. make_ambig_note(ambig, ambig_letter_list) .. '</div>'
	
	return '<div class="vsSwitcher" data-toggle-category="pronunciations" style="width: ' .. inlineIPAlength .. 'em; max-width:100%;"><span class="vsToggleElement" style="float: right;">&nbsp;</span>' .. inline .. full .. '\n</div>'
end

function export.create(frame)
	local params = {
		[1] = {default = pagename},
		["period"] = {default = "cla"},
	}
	local args = require("Module:parameters").process(frame.getParent and frame:getParent().args or frame, params, nil, "grc-pronunciation", "create")
	
	local term = ulower(args[1])
	local old = term
	term = m_utils.standardDiacritics(term)
	term = mark_implied_length(term)
	--[[
	if toNFD(old) ~= term then
		mw.log(old .. " > " .. term)
	end
	]]
	
	local decomposed = toNFD(term)
	if rfind(decomposed, "[εοηω]" .. m_utils_data.diacritic .. "*[" .. diacritics.spacing_macron .. diacritics.spacing_breve .. diacritics.breve .. diacritics.macron .. "]") then
		error("Macrons and breves cannot be placed after the letters ε, ο, η, or ω.")
	end
	
	local ambig, ambig_letter_list
	if args.period == "cla" then
		ambig, ambig_letter_list = m_utils.findAmbig(term)
	end
	term = rsubn(term, 'ς', 'σ')
	term = rsubn(term, 'ῤ', 'ρ')
	term = rearrangeDiacritics(term)
	
	local IPAs, periods = convert_term(term, args.period)
	
	IPAs = syllabify(IPAs, periods)
	
	return make_table(IPAs, ambig, periods, ambig_letter_list)
end

function export.example(frame)
	local output = { '{| class="wikitable"' }
	
	local params = {
		[1] = {}
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params, nil, "grc-pronunciation", "example")
	
	local terms = mw.text.split(args[1], ",%s+")
	
	for _, term in pairs(terms) do
		local period = rmatch(term, "%(period ?= ?([^%)]+)%)") or "cla"
		local entry = rmatch(term, "([^%(]+) %(") or term or error('No term found in "' .. term .. '".') 
		local link = full_link(entry)
		local IPA = export.create{ entry, ["period"] = period }
		table.insert(output, "\n|-\n| " .. link .. " || " .. IPA)
	end
	
	table.insert(output, "\n|}")
	
	return table.concat(output)
end

return export
--Things we still need:
--Voicing of sigma around (after?) voiced stops. 
--Proper alerts for editors, especially on ambiguous vowels.
"https://si.wiktionary.org/w/index.php?title=Module:grc-pronunciation&oldid=168661" වෙතින් සම්ප්‍රවේශනය කෙරිණි