local export = {}
--[=[
This module contains driver code for running a given set of testcases for ]. The testcases are
split into multiple subsets for different lects, and also to allow for splitting within a given lect if there end up
being too many to include in a single module (because of time-expired errors).
To create a new subset, copy an existing subset and modify the examples, and set up the corresponding documentation page
as appropriate. For example, to create a subset specifically for English-origin words, copy an existing page such as
] to e.g. ]. Also copy the documentation
page ] to e.g.
], modifying the module invocation reference in the
documentation page as appropriate to point to your subset module. Then modify the examples in e.g.
] according to the following format.
Each line of the example text is either a high-level header beginning with ###, a subheader beginning with ##, a comment
beginning with #, a blank line or an example. Examples consist of three tab-separated fields, followed by an optional
comment to be shown along with the example (delimited by a # preceded by whitespace). The first field is the actual
spelling of the term in question. The second field is the respelling, or # if the respelling is the same as the
spelling. The third field is the expected IPA pronunciation (without slashes or brackets).
]=]
local m_zlw_lch_IPA = require("Module:zlw-lch-IPA")
local m_links = require("Module:links")
-- FIXME
local lang = require("Module:languages").getByCode("pl")
local rsplit = mw.text.split
local rmatch = mw.ustring.match
local function tag_IPA(IPA)
return '<span class="IPA">' .. IPA .. "</span>"
end
local function link(text)
return m_links.full_link{ term = text, lang = lang }
end
local options = { display = tag_IPA }
function export.check_ipa(self, lang, lect, spelling, respelling, expected, comment)
if respelling == "#" then
respelling = spelling
end
local pron_list =
m_zlw_lch_IPA.get_lect_pron_info({{respelling = respelling}}, spelling, "", lang, lect).pron_list
local phonemic = {}
for _, pron in ipairs(pron_list) do
local syldiv_pron = pron.pron_with_syldivs
syldiv_pron = syldiv_pron:gsub("^/(.*)/$", "%1")
table.insert(phonemic, syldiv_pron)
end
phonemic = table.concat(phonemic, ",")
options.comment = comment or ""
self:equals(
link(spelling) .. (respelling == spelling and "" or ", respelled " .. respelling),
phonemic,
expected,
options
)
end
function export.parse(examples)
-- The following is a list of parsed examples where each element is a four-element list of
-- {SPELLING, RESPELLING, EXPECTED, COMMENT}. SPELLING is the actual spelling of the term; RESPELLING is the
-- respelling; EXPECTED is the phonemic IPA; and COMMENT is an optional comment or nil.
local parsed_examples = {}
-- Snarf each line.
for line in examples:gmatch "+" do
-- Trim whitespace at beginning and end.
line = line:gsub("^%s*(.-)%s*$", "%1")
local function err(msg)
error(msg .. ": " .. line)
end
if line == "" then
-- Skip blank lines.
elseif line:find("^###") then
-- Line beginning with ### is a high-level header.
line = line:gsub("^###%s*", "")
table.insert(parsed_examples, "#h1:" .. line)
elseif line:find("^##") then
-- Line beginning with ## is a subheader.
line = line:gsub("^##%s*", "")
table.insert(parsed_examples, line)
elseif line:find("^#") then
-- Line beginning with # is a comment; ignore.
else
local line_no_comment, _, _, _, comment = rmatch(line, "^((*)\t(*)\t(-))%s+#%s*(.*)$")
line_no_comment = line_no_comment or line
local parts = rsplit(line_no_comment, "\t")
if #parts ~= 3 then
err("Expected 3 tab-separated components in example (not including any comment)")
end
table.insert(parts, comment)
table.insert(parsed_examples, parts)
end
end
return parsed_examples
end
return export