10,794
edits
TheNightAvl (talk | contribs) mNo edit summary |
TheNightAvl (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
function export.main(frame) | |||
local args = getArgs(frame) | |||
local | return export.generate(args) | ||
end | |||
local data = { | local data = { | ||
Line 120: | Line 118: | ||
end | end | ||
-- BEGIN BASE GENERATION -- | -- BEGIN BASE GENERATION -- | ||
function | function generate_IPA(s) | ||
local s_len = | local s_len = utf8.len(s) | ||
IPA = {} | IPA = {} | ||
local split_s = {} | local split_s = {} | ||
for i = 1, s_len do | for i = 1, s_len do | ||
split_s[i] = | split_s[i] = string.sub(s, i,i) | ||
end | end | ||
if s_len == 0 then | if s_len == 0 then | ||
error("Empty input.") | error("Empty input.") | ||
end | end | ||
while s_len > 0 do | while s_len > 0 do | ||
local getData = {} | local getData = {} | ||
local multiMatch = false | local multiMatch = false | ||
local i_iteration = -2 | local i_iteration = -2 | ||
print("\n=========================\n\nCURRENT TEST STRING: <".. s:upper() .. ">") | |||
if s_len < 3 then | if s_len < 3 then | ||
i_iteration = 1 - s_len | i_iteration = 1 - s_len | ||
end | end | ||
for i = i_iteration, 0 do | for i = i_iteration, 0 do | ||
print("————— <" .. split_s[s_len + i] .. "> selected. (i = " .. i .. ") —————") | |||
getData = data[split_s[s_len + i]] | getData = data[split_s[s_len + i]] | ||
local deadEnd = false | local deadEnd = false | ||
if data[split_s[s_len + i]] == nil then | if data[split_s[s_len + i]] == nil then | ||
error("'" .. split_s[s_len + i] .. "' is an invalid character.") | error("'" .. split_s[s_len + i] .. "' is an invalid character.") | ||
end | end | ||
while type(getData) == "table" do | while type(getData) == "table" do | ||
if i == 0 then | if i == 0 then | ||
if getData[false] then | if getData[false] then | ||
print("Singular index recognised.") | |||
getData = getData[false] | getData = getData[false] | ||
print("Index acquired: " .. getData) | |||
else | else | ||
error(split_s[s_len] .. " is an invalid character.") | error(split_s[s_len] .. " is an invalid character.") | ||
end | end | ||
else | else | ||
print("Tabular index recognised.") | |||
for j = 1, 0 - i do | for j = 1, 0 - i do | ||
-- DEBUG PRINT ONLY | -- DEBUG PRINT ONLY | ||
Line 160: | Line 171: | ||
end | end | ||
-- END OF DEBUG PRINT | -- END OF DEBUG PRINT | ||
print("Testing " .. currentCombo) | |||
if getData[split_s[s_len + i + j]] then | if getData[split_s[s_len + i + j]] then | ||
getData = getData[split_s[s_len + i + j]] | getData = getData[split_s[s_len + i + j]] | ||
print("Combination recognised: " .. currentCombo .. " (j = " .. j .. ")") | |||
if type(getData) == "string" then | if type(getData) == "string" then | ||
if j + i == 0 then | if j + i == 0 then | ||
print("Index acquired: " .. getData) | |||
multiMatch = true | multiMatch = true | ||
break | break | ||
else | else | ||
print('Non-final index: dead end.') | |||
getData = {} | getData = {} | ||
deadEnd = true | deadEnd = true | ||
break | break | ||
end | end | ||
elseif j + i == 0 and getData[false] then | elseif j + i == 0 and getData[false] then | ||
getData = getData[false] | getData = getData[false] | ||
print("Index acquired: " .. getData) | |||
multiMatch = true | multiMatch = true | ||
break | break | ||
Line 178: | Line 196: | ||
error("data[" .. table.concat(getData, "][") .. "][false] is missing." ) | error("data[" .. table.concat(getData, "][") .. "][false] is missing." ) | ||
else | else | ||
print("Target still tabular: reiterating.") | |||
end | end | ||
else | else | ||
print('Dead end.') | |||
getData = {} | getData = {} | ||
deadEnd = true | deadEnd = true | ||
Line 189: | Line 209: | ||
end | end | ||
if type(getData) == "string" and (i == 0 or multiMatch == true) then | if type(getData) == "string" and (i == 0 or multiMatch == true) then | ||
print("Target acquired of length " .. 1 - i .. ", converting to [" .. getData .. "].") | |||
append_IPA(getData) | append_IPA(getData) | ||
s = | s = string.sub(s, 1, s_len + i - 1) | ||
s_len = | s_len = string.len(s) | ||
break | break | ||
elseif deadEnd == false then | elseif deadEnd == false then | ||
print('Non-final index: dead end.') | |||
end | end | ||
end | end | ||
end | end | ||
print('\n————— STRING EXHAUSTED —————') | |||
return table.concat(IPA) | return table.concat(IPA) | ||
-- END OF BASE GENERATION -- | -- END OF BASE GENERATION -- | ||
end | end | ||
function export.generate(frame) | function export.generate(frame) | ||
local args = | local args = frame:getParent().args | ||
return export.generate_IPA | return export.generate_IPA(args[1]) | ||
end | end | ||
return export | return export |