Module:R:Perseus/polytonic-to-perseus-betacode

Hello, you have come here looking for the meaning of the word Module:R:Perseus/polytonic-to-perseus-betacode. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:R:Perseus/polytonic-to-perseus-betacode, but we will also tell you about its etymology, its characteristics and you will know how to say Module:R:Perseus/polytonic-to-perseus-betacode in singular and plural. Everything you need to know about the word Module:R:Perseus/polytonic-to-perseus-betacode you have here. The definition of the word Module:R:Perseus/polytonic-to-perseus-betacode will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:R:Perseus/polytonic-to-perseus-betacode, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local u = mw.ustring.char
local ulower = mw.ustring.lower

local letters = {
	 = "a",  = "b",  = "g",  = "d",  = "e",  = "v",
	 = "#2",  = "z",  = "h",  = "q",  = "i",  = "k",
	 = "l",  = "m",  = "n",  = "c",  = "o",  = "p",
	 = "#1",  = "#3",  = "r",  = "s",  = "s",  = "s3",
	 = "t",  = "u",  = "f",  = "x",  = "y",  = "w",
	 = "#5", 
	 = ")",  = ")",  = ")",  = ")",  = ")", -- psili
	 = "(",  = "(",  = "(", --
	 = "/",  = "/",  = "/",  = "/",  = "/", -- acute
	 = "=",  = "=", -- perispomeni
	 = "\\",  = "\\",  = "\\",  = "\\", -- grave
	 = "+",  = "+", -- dialytika
	 = "|",  = "|", -- ypogegrammeni
	 = "?",
	 = ":",  = ":", -- ano teleia
	 = ";", -- erotimatiko
	 = "", -- macron
	 = "", -- breve
	 = "",  = "", -- hyphen
	 = "'" -- apostrophe
}

local function convert(ch)
	local ret = letters
	if ret then
		return ret
	end
	local ch_lower = ulower(ch)
	if ch_lower ~= ch then
		ret = letters
		if ret then
			ret = "*" .. ret
		end
	end
	return ret
end

local function handle_char(base, diacritics, pre)
	local set = ")(/\\=|+"
	if pre then
		set = set:reverse()
	end
	for ch in (set):gmatch(".") do
		if diacritics:find(ch, nil, true) then
			if pre then
				base = ch .. base
			else
				base = base .. ch
			end
		end
	end
	return (pre and "*" or "") .. base
end

function export.polytonic_to_perseus_betacode(polytonic)
	return toNFC(toNFD(polytonic):gsub(".*", convert)
		:gsub("%*(%l)(+)()", handle_char)
		:gsub("%*(#%d+)(+)()", handle_char)
		:gsub("(%l)(+)", handle_char)
		:gsub("(#%d+)(+)", handle_char)
	)
end

return export