Module:X2i Explained

local p =

local U = mw.ustring.char-- Slashes \, apostrophes ', and double quotes " are escaped with \.-- \\ = \, \' = ', \" = "

local data =

local function escape(text, pattern, list, i) text = mw.ustring.gsub(text, pattern, function(match) list[i] = match local replacement = string.rep("$", i) i = i + 1 return replacement end )

return textend

local function _XSAMPAtoIPA(text) local output = local characteristics = local escaped = local i = 1 local toBeEscaped =

for i, pattern in pairs(toBeEscaped) do text = mw.ustring.gsub(text, pattern, function(match) escaped[i] = match local replacement = string.rep("$", i) .. "*" i = i + 1 return replacement end ) end mw.log(i, #escaped, text) mw.logObject(escaped) while #text > 0 do local substrings = for i, substring in ipairs(substrings) do local result, IPA, with_descender, has_descender, is_diacritic if data[substring] then result = data[substring] IPA = result[1] with_descender = result.with_descender has_descender = result.has_descender diacritic = result.is_diacritic if with_descender then -- Go backwords through the transcription, skipping any diacritics. local i = 0 while characteristics[#characteristics - i].is_diacritic do i = i + 1 end --Look at the first non-diacritic symbol before the current symbol. If it has a descender, use the descender form of the current symbol. if characteristics[#characteristics - i].has_descender then IPA = with_descender end end elseif not substrings[i + 1] then IPA = substring end if IPA then text = mw.ustring.sub(text, 6 - i) table.insert(output, IPA) table.insert(characteristics,) break end end end output = table.concat(output) output = mw.ustring.gsub(output, "($+)%*", function(match) local i = string.len(match) return escaped[i] end ) return outputend

function p.X2IPA(frame) local text if type(frame)

"table" then text = frame.getParent and frame:getParent.args[1] or frame.args and frame.args[1] else text = frame end return _XSAMPAtoIPA(text)end

local function _IPAspan(text) return "

"..text..""end

function p.example(frame) local args = frame.args local parentargs = frame.getParent and frame:getParent.args local text = parentargs and parentargs[1] or args and args[1] or type(frame)

"string" and frame or error("No text provided") local output = if mw.ustring.find(text, "=") then table.insert(output, "1=") end table.insert(output, text) table.insert(output, "}}") table.insert(output, "\n| ") local IPA = _IPAspan(p.X2IPA(text)) table.insert(output, IPA) return table.concat(output)end

return p