local data = {}

local U = require("Module:string/char")

local candrabindu = U(0xC81)
local anusvAra = U(0xC82)
local visarga = U(0xC83)
local virAma = U(0xCCD)
local nuktA = U(0xCBC)
local avagraha = "ಽ"
local consonants = "ಕಖಗಘಙಚಛಜಝಞಟಠಡಢಣತಥದಧನಪಫಬಭಮಯರಱಲವಶಷಸಹಳೞ"
local consonant = "[" .. consonants .. "]" .. nuktA .. "?"

local acute = U(0x301)		-- combining acute

data["pra-Knda"] = {
-- Two-element vowels or vowel seqeunces.
	{"a[iuïüö]", {["ai"] = "ಐ", ["au"] =  "ಔ", ["aï"] = "ಅಇ", ["aü"] = "ಅಉ",
			["aö"] = "ಅಓ"}},
	{"l̥̄", "ೡ"},
	{"l̥", "ಌ"},
-- Digraphs with 'h':
	{".h", {["kh"] = "ಖ", ["gh"] = "ಘ", ["ch"] = "ಛ", ["jh"] = "ಝ",
			["ṭh"] = "ಠ", ["ḍh"] = "ಢ", ["th"] = "ಥ", ["dh"] = "ಧ",
			["ph"] = "ಫ", ["bh"] = "ಭ",}},
-- Non-ASCII single characters
	{".",  {["ḹ"] = "ೡ", ["ṃ"] = anusvAra, ["ḥ"] = visarga,
			["ṅ"] = "ಙ", ["ñ"] = "ಞ", ["ṇ"] = "ಣ", ["ś"] = "ಶ",
			["ṣ"] = "ಷ", ["ā"] = "ಆ", ["ī"] = "ಈ", ["ū"] = "ಊ",
			["ĕ"] = "ಎ", ["ŏ"] = "ಒ", ["ṝ"] = "ೠ", ["ḷ"] = "ಳ",
			["ṭ"] = "ಟ", ["ḍ"] = "ಡ", ['̈'] = "", 	["ṛ"] = "ಋ",}},
-- ASCII letters
	{"[a-z]",  {n = "ನ", m = "ಮ", y = "ಯ", r = "ರ",
				l = "ಲ", v = "ವ", s = "ಸ", a = "ಅ",
				i = "ಇ", u = "ಉ", e = "ಏ", o = "ಓ",
				k = "ಕ", g = "ಗ", c = "ಚ", j = "ಜ",
				t = "ತ", d = "ದ", p = "ಪ", b = "ಬ",
				h = "ಹ"}},
	{"(ಅ)[%-/]([ಇಉ])", "%1%2"},		-- a-i, a-u for 𑀅𑀇, 𑀅𑀉; must follow rules for "ai", "au"
	{"(" .. consonant .. ")$", "%1" .. virAma},
	{acute, ""},
	-- this rule must be applied twice because a consonant may only be in one capture per operation, so "CCC" will only recognize the first two consonants
	{"(" .. consonant .. ")" .. "(" .. consonant .. ")", "%1" .. virAma .. "%2"},
	{"(" .. consonant .. ")" .. "(" .. consonant .. ")", "%1" .. virAma .. "%2"},
	{"i", "ಇ"},
	{"u", "ಉ"},
}

local vowels = {
	["ಇ"] = U(0xCBF),
	["ಉ"] = U(0xCC1),
	["ಋ"] = U(0xCC3),
	["ಌ"] = U(0xCE2),
	["ಎ"] = U(0xCC6),
	["ಏ"] = U(0xCC7),
	["ಒ"] = U(0xCCA),
	["ಓ"] = U(0xCCB),
	["ಆ"] = U(0xCBE),
	["ಈ"] = U(0xCC0),
	["ಊ"] = U(0xCC2),
	["ೠ"] = U(0xCC4),
	["ೡ"] = U(0xCE3),
	["ಐ"] = U(0xCC8),
	["ಔ"] = U(0xCCC),
}

for independentForm, diacriticalForm in pairs(vowels) do
	table.insert(data["pra-Knda"], {"(" .. consonant .. ")" .. independentForm, "%1" .. diacriticalForm})
end

-- This must go last, after independent vowels are converted to diacritics, or "aï", "aü" won't work.
table.insert(data["pra-Knda"], {"(" .. consonant .. ")ಅ", "%1"})

-- [[w:Harvard-Kyoto]] to [[w:International Alphabet of Sanskrit Transliteration]]
data["pra-Knda-tr"] = {
	[1] = {
		["A"] = "ā",
		["I"] = "ī",
		["U"] = "ū",
		["J"] = "ñ",
		["T"] = "ṭ",
		["D"] = "ḍ",
		["N"] = "ṇ",
		["G"] = "ṅ",
		["z"] = "ś",
		["S"] = "ṣ",
		["M"] = "ṃ",
		["H"] = "ḥ",
		["lRR"] = "ḹ",
		["/"] = acute,
	},
	[2] = {
		["lR"] = "ḷ",
		["RR"] = "ṝ",
	},
	[3] = {
		["R"] = "ṛ",
	},
}

return data
"https://si.wiktionary.org/w/index.php?title=Module:typing-aids/data/pra-Knda&oldid=193544" වෙතින් සම්ප්‍රවේශනය කෙරිණි