Module:Smyth: Difference between revisions

Content deleted Content added
debug, allow multiple separators
Misc code cleanup, remove functions and variables used only once
 
(17 intermediate revisions by 2 users not shown)
Line 1:
local export = {}
 
local function Smyth(section, part)
data = {
["Smyth"] = {
["path"] = "1999.04.0007",
["parts"] = { "part", "chapter", "section", "smythp" }
}
}
 
local function url(resourceCode, part, code)
code = mw.uri.encode(code, PATH)
return "http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:" .. path .. ":" .. part .. "=" .. code
end
 
function Smyth(section, part)
if not part then
part = "smythp"
end
local Part, url
SmythData = data.Smyth
if section[n] == nil"" or section[n] == ""nil then
path = SmythData.path
url, Part = "No number provided", "No number provided"
return url(path, part, section)
else
sectionNumber = tonumber(section)
if sectionNumber == nil then
Part = ""
else
if sectionNumber < 189 then
Part = "Part I: Letters, Sounds, Syllables, Accent"
elseif sectionNumber < 822 then
Part = "Part II: Inflection"
elseif sectionNumber < 900 then
Part = "Part III: Formation of Words"
elseif sectionNumber < 3049 then
Part = "Part IV: Syntax"
endelse
error("The largest valid section number is 3048")
end
end
code section = mw.uri.encode(codesection, "PATH")
return url = "http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:" 1999.04. path .. "0007:" .. part .. "=" .. codesection
end
return { url = url, Part = Part }
end
 
function export.SmythSection(frame)
local outputsectionParameter = ""frame.args[1]
local sectionsoutput, sign = frame.args[1]"", ""
local sectionsections, postscripts, separators = {}, {}, {}
local part = frame.args[2]
if sectionssectionParameter then
n = 1
if mw.ustring.find(sectionParameter, "[^%d%s]") then
for separator, number in string.gmatch(sections, "([^%d]*)(%d+)") do
for number, postscript, separator in mw.ustring.gmatch(sectionParameter, "(%d+ ?%u?)(%.?[%l%d]?)(%p?[^%d]*)") do
section[n] = number
sections[n], postscripts[n], separators[n] = number, postscript, separator
if separator == "" or separator == nil then
separatorsif sections[n] == "" or sections[n] == nil then
else break
end
separators[n] = separator
n = n + 1
end
else
if section[n] == nil or section[n] == "" then
sections[1], separators[1] = mw.ustring.match(sectionParameter, "(%d+)"), ""
n = false
end
n = n + 1
end
else
error("SmythSection wants input in the first parameter")
end
if #sections == nil then
for i = 1, #section do
error("No numbers in the text provided to SmythSection")
output = output .. separators[i] .. "[" .. Smyth(section[i]) .. " " .. section[i] .. "]"
if elseif separatorsections[2] == "" or separatorsections[2] == nil then
sign = "§"
else
sign = "§§"
end
for i = 1, #sectionsections do
if sections[i] == "" or sections[i] == nil then -- Does gmatch return nil or an empty string when it finds no match?
break
else
if not postscripts[i] then postscripts[i] = "" end
if not separators[i] then separators[i] = "" end
output = output .. separators[i] .. "[" .. Smyth(sectionsections[i]).url .. " " .. section[i] .. "]"
if i == 1 then
output = output .. sign .. "&nbsp;"
end
output = output .. sections[i] .. postscripts[i] .. "]" .. separators[i]
end
end
return output
end
 
function export.SmythPart(frame)
local sectionParameter = frame.args[1]
local section = mw.ustring.match(sectionParameter, "(%d+)")
return urlSmyth(path, part, section).Part
end