Module:Ancient Greek/typing explained

local p =

local sparse_concat = require("Module:TableTools").sparseConcatlocal U = mw.ustring.char

local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*" -- roughly equivalent to "." in Ustring patternslocal one_UTF8_char_or_none = "[%z\1-\127\194-\244]?[\128-\191]*" -- roughly equivalent to ".?" in Ustring patterns

local subscript = U(0x345) -- iota subscript (ypogegrammeni)local macron = U(0x304) -- macronlocal spacing_macron = U(0xAF)local modifier_macron = U(0x2C9) -- modifier letter macronlocal breve = U(0x306) -- brevelocal spacing_breve = "˘" -- spacing brevelocal diaeresis = U(0x308) -- diaeresislocal rough = U(0x314) -- rough breathing (reversed comma)local smooth = U(0x313) -- smooth breathing (comma)local acute = U(0x301) -- acutelocal grave = U(0x300) -- gravelocal circumflex = U(0x342) -- Greek circumflex (perispomeni)local question_mark = U(0x37E) -- Greek question marklocal spacing_rough = "῾" -- spacing rough breathinglocal spacing_smooth = "᾿" -- spacing smooth breathing

local combining_diacritic = table.concat

-- The numbers are used to sort series of diacritics.local diacritic_position =

-- Perform a function on each Unicode character in a string.local function for_each(str, func) for char in string.gmatch(str, UTF8_char) do func(char) endend

--[=[ This function arranges diacritics in the following order: 1. macron or breve 2. breathings or diaeresis 3. acute, circumflex, or grave 4. iota subscript Used by [[Module:typing-aids]]. Returns an error if a sequence of diacritics contains more than one of each category.]=]local function get_relative_position(diacritic1, diacritic2) return diacritic_position[diacritic1] < diacritic_position[diacritic2]end

local function chars_to_table(chars) local t = local i = 0 for char in string.gmatch(chars, "[%z\1-\127\194-\244][\128-\191]*") do i = i + 1 t[i] = char end return tend

local function reorder_diacritic_sequence(diacritics) diacritics = chars_to_table(diacritics) table.sort(diacritics, get_relative_position) return table.concat(diacritics)end

function p.reorder_diacritics(text) return (mw.ustring.gsub(mw.ustring.toNFD(text), combining_diacritic .. combining_diacritic .. "+", reorder_diacritic_sequence))end

local multiple =

local single =

local function convert_s_to_sigma(text) text = string.gsub(text, "s(" .. one_UTF8_char_or_none .. ")", function (following) return ((following

"" or following ~= "*" and following ~= "-" and mw.ustring.find(following, "[%s%p]")) and "ς" or "σ") .. following end) return textend

local function combining_to_spacing(text) for _, accents in ipairs do local combining, spacing = unpack(accents) text = string.gsub(text, "(" .. one_UTF8_char_or_none .. ")" .. combining, function (preceding) if preceding

"" then return spacing else return preceding .. combining end end) end return textend

function p.to_Greek(text) if type(text) ~= "string" then error("first argument to to_greek should be string, not " .. type(text)) end text = convert_s_to_sigma(text) for k, v in pairs(multiple) do text = string.gsub(text, k, v) end text = string.gsub(text, UTF8_char, single) text = combining_to_spacing(text) return p.reorder_diacritics(text)end

function p.to_Greek_t(frame) local args = for k, v in pairs(frame:getParent.args) do if k

1 then v = mw.text.trim(v) if v

"" then v = nil end args[k] = v end end if not args[1] then if mw.title.getCurrentTitle.nsText

"Template" then args[1] = "le/cis" else error("Parameter 1 is required.") end end return p.to_Greek(args[1])end

local function process(char) if char

"" then return char end local entity = ("&#x%X;"):format(mw.ustring.codepoint(char)) if diacritic_position[char] then return "◌" .. entity else return entity endend

function p.show_shortcuts(frame) local output = ') return table.concat(output, '\n') end

return p