This module is used by {{R:Smyth}}
to generate links to sections of Smyth's Greek Grammar, and to determine the name of the Part in which the section is found.
* {{#invoke:R:Smyth|section|2023, 2024}} * {{#invoke:R:Smyth|section|25: diphthongs}} * {{#invoke:R:Smyth|Part|2023, 2024}} * {{#invoke:R:Smyth|Part|25: diphthongs}}
export = {}
local path = "1999.04.0007"
local find, match, gmatch = mw.ustring.find, mw.ustring.match, mw.ustring.gmatch
local function makeURL(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
if section == "" or section == nil then
url, Part = "No number provided", "No number provided"
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"
else
error("The largest valid section number is 3048")
end
end
url = makeURL(path, part, section)
end
return { url = url, Part = Part }
end
function export.section(frame)
local sectionParameter, part = frame.args, frame.args
local output, sign = "", ""
local sections, postscripts, separators = {}, {}, {}
if sectionParameter and sectionParameter ~= "" then
n = 1
if find(sectionParameter, "") then
for number, postscript, separator in gmatch(sectionParameter, "(%d+ ?%u?)(%.??%.??)(%p?*)") or gmatch(sectionParameter, "(%d+ ?%u?)(%.??)(%p?*)") do
sections, postscripts, separators = number, postscript, separator
if sections == "" or sections == nil then
break
end
n = n + 1
end
else
sections, separators = match(sectionParameter, "(%d+)"), ""
end
else
error("SmythSection wants input in the first parameter")
end
if #sections == 0 then
error("No numbers in the text provided to SmythSection")
elseif sections == "" or sections == nil then
sign = "§"
else
sign = "§§"
end
for i = 1, #sections do
if sections == "" or sections == nil then -- Does gmatch return nil or an empty string when it finds no match?
break
else
if not postscripts then postscripts = "" end
if not separators then separators = "" end
output = output .. ").url .. " "
if i == 1 then
output = output .. sign .. " "
end
output = output .. sections .. postscripts .. "]" .. separators
end
end
return output
end
function export.Part(frame)
local sectionParameter = frame.args
local section = match(sectionParameter, "(%d+)")
return Smyth(section).Part
end
return export