local lang = require("Module:languages").getByCode("fa")
local export = {}
local pos_functions = {}
local u = mw.ustring.char
local A = u(0x064E) -- fatḥa
local AN = u(0x064B) -- fatḥatān (fatḥa tanwīn)
local U = u(0x064F) -- ḍamma
local I = u(0x0650) -- kasra
local SK = u(0x0652) -- sukūn = no vowel
local SH = u(0x0651) -- šadda = gemination of consonants
-----------------------
-- Utility functions --
-----------------------
-- If Not Empty
local function ine(arg)
if arg == "" then
return nil
else
return arg
end
end
-- version of mw.ustring.gsub() that discards all but the first return value
function rsub(term, foo, bar)
local retval = mw.ustring.gsub(term, foo, bar)
return retval
end
local rfind = mw.ustring.find
-- Tracking functions
local trackfn = require("Module:debug/track")
function track(page)
trackfn("fa-headword/" .. page)
return true
end
function remove_links(text)
text = rsub(text, "%]*|", "")
text = rsub(text, "%[%[", "")
text = rsub(text, "%]%]", "")
return text
end
local function make_unused_key_tracker(t)
local unused_keys = require"Module:table".listToSet(
require"Module:table".keysToList(t))
local mt = {
__index = function(self, key)
if key ~= nil then unused_keys = nil end
return t
end,
__newindex = function(self, key, value) t = value end
}
local proxy_table = setmetatable({}, mt)
return proxy_table, unused_keys
end
function export.ZWNJ(word)
if mw.ustring.match(word,
"",
-1) then
return "\226\128\140" -- U+200C ZERO WIDTH NON-JOINER
end
return "" -- empty string
end
-- The main entry point.
function export.show(frame)
local PAGENAME = mw.loadData("Module:headword/data").pagename
local poscat = frame.args or error(
"Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local params = {
= {list = "head", allow_holes = true, default = ""},
= {default = ""},
= {list = true, allow_holes = true}
}
local args, unused_keys = make_unused_key_tracker(frame:getParent().args)
-- Gather parameters
local data = {
lang = lang,
pos_category = poscat,
categories = {},
heads = {},
translits = {},
inflections = {}
}
local saw_head = false
local head = ine(args) or ine(args)
if head then
saw_head = true
else
head = PAGENAME
end
local translit = ine(args)
local i = 1
while head do
table.insert(data.heads, head)
data.translits = translit
i = i + 1
head = ine(args)
if head then
saw_head = true
end
translit = ine(args)
end
data.no_redundant_head_cat = not saw_head
if pos_functions then pos_functions.func(args, data) end
local unused_key_list = require"Module:table".keysToList(unused_keys)
if #unused_key_list > 0 then
local unused_key_string = require "Module:array"(unused_key_list):map(
function(key)
return "|" .. key .. "=" .. args
end):concat("\n")
error("Unused arguments: " .. unused_key_string)
end
return require("Module:headword").full_headword(data)
end
-- Get a list of inflections. See handle_infl() for meaning of ARGS, ARGPREF
local function getargs(args, argpref)
-- Gather parameters
local forms = {}
local form = ine(args)
local translit = ine(args)
local i = 1
while form do
table.insert(forms, {term = form, translit = translit})
i = i + 1
form = ine(args)
translit = ine(args)
end
return forms
end
local function handle_infl(args, data, argpref, label)
local newinfls = getargs(args, argpref)
newinfls.label = label
if #newinfls > 0 then table.insert(data.inflections, newinfls) end
end
local function handle_all_infl(args, data, argpref, label, nobase)
if not nobase and argpref ~= "" then
handle_infl(args, data, argpref, label)
end
end
pos_functions = {
func = function(args, data)
data.pos_category = "verbs"
handle_all_infl(args, data, "prstem", "present stem")
end
}
pos_functions = {
func = function(args, data)
data.pos_category = "adjectives"
if ine(args) and args == "+" then
local word = data.heads
local word_tr = args
table.insert(data.inflections, {
label = "comparative",
accel = {form = "comparative", translit = word_tr .. "-tar"},
{
term = word .. export.ZWNJ(word) .. "ت" .. A .. "ر",
translit = word_tr .. "-tar"
}
})
table.insert(data.inflections, {
label = "superlative",
accel = {form = "superlative", translit = word_tr .. "-tarin"},
{
term = word .. export.ZWNJ(word) .. "ت" .. A .. "رین",
translit = word_tr .. "-tarin"
}
})
end
end
}
return export