Content deleted Content added
adding a function to generate Part names for Smyth refs; this is much simpler than using a template since regex has to be used to find the first number |
Misc code cleanup, remove functions and variables used only once |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 1:
local export = {}
local function Smyth(section, part)▼
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
url, Part = "No number provided", "No number provided"
▲ local Part = ""
sectionNumber = tonumber(section)▼
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"▼
else
error("The largest valid section number is 3048")▼
if sectionNumber == nil then
Part = ""
▲ Part = "Part I: Letters, Sounds, Syllables, Accent"
▲ Part = "Part II: Inflection"
▲ Part = "Part III: Formation of Words"
▲ Part = "Part IV: Syntax"
▲ error("The largest valid section number is 3048")
▲ end
▲
end
return { url = url
end
Line 39 ⟶ 34:
local sectionParameter = frame.args[1]
local output, sign = "", ""
local sections, postscripts, separators = {}, {}, {}
local part = frame.args[2]
if sectionParameter then
n = 1
if mw.ustring.find(sectionParameter, "[^%d%s]") then
for number, postscript, separator in mw.ustring.gmatch(sectionParameter, "(%d
▲ if number == "" or number == nil then
▲ else
▲ end
▲ else
▲ if sections[n] == "" and separators[n] == "" then
break
end
Line 61 ⟶ 47:
end
else
sections[1], separators[1] = mw.ustring.match(sectionParameter, "(%d
end
else
error("SmythSection wants input in the first parameter")
end
if #sections == nil
error("No numbers in the text provided to SmythSection")
elseif sections[2] == "" or sections[2] == nil then
sign = "§"
else
Line 74 ⟶ 60:
end
for i = 1, #sections 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 .. "[" .. Smyth(
if i == 1 then
output = output ..
end
output = output ..
end
end
Line 90 ⟶ 77:
function export.SmythPart(frame)
local sectionParameter = frame.args[1]
local section = mw.ustring.match(sectionParameter, "(%d+)")
return Smyth(section).Part
end
|