Module:affix/templates: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 11: Line 11:
end
end


local recognized_affix_types = {
prefix = "prefix",
pre = "prefix",
suffix = "suffix",
suf = "suffix",
interfix = "interfix",
inter = "interfix",
infix = "infix",
["in"] = "infix",
circumfix = "circumfix",
circum = "circumfix",
["non-affix"] = "non-affix",
naf = "non-affix",
root = "non-affix",
}
local function pre_normalize_affix_type(data)
local modtext = data.modtext
modtext = modtext:match("^<(.*)>$")
if not modtext then
error(("Internal error: Passed-in modifier isn't surrounded by angle brackets: %s"):format(data.modtext))
end
if recognized_affix_types[modtext] then
modtext = "type:" .. modtext
end
return "<" .. modtext .. ">"
end


-- Parse raw arguments. A single parameter `data` is passed in, with the following fields:
-- Parse raw arguments. A single parameter `data` is passed in, with the following fields:
Line 23: Line 51:
-- * `require_index_for_pos`: There is no separate |pos= parameter distinct from |pos1=, |pos2=, etc. Instead,
-- * `require_index_for_pos`: There is no separate |pos= parameter distinct from |pos1=, |pos2=, etc. Instead,
--  specifying |pos= results in an error.
--  specifying |pos= results in an error.
-- * `allow_type`: Allow |type1=, |type2=, etc. or inline <type:...> for the affix type, and allow a separate |type=
--  parameter for the etymology type (FIXME: this may be confusing; consider changing the etymology type to |etype=).
--
--
-- Note that all language parameters are allowed to be etymology-only languages.
-- Note that all language parameters are allowed to be etymology-only languages.
Line 58: Line 88:


     local m_param_utils = require(parameter_utilities_module)
     local m_param_utils = require(parameter_utilities_module)
local param_mods = m_param_utils.construct_param_mods {
local param_mod_source = {
-- We want to require an index for all params (or use separate_no_index, which also requires an index for the
-- We want to require an index for all params (or use separate_no_index, which also requires an index for the
-- param corresponding to the first item).
-- param corresponding to the first item).
Line 67: Line 97:
{param = "pos", separate_no_index = not data.require_index_for_pos, require_index = data.require_index_for_pos},
{param = "pos", separate_no_index = not data.require_index_for_pos, require_index = data.require_index_for_pos},
}
}
if data.allow_type then
table.insert(param_mod_source, {param = "type", separate_no_index = true})
end
local param_mods = m_param_utils.construct_param_mods(param_mod_source)
if data.extra_params then
if data.extra_params then
data.extra_params(params)
data.extra_params(params)
Line 82: Line 117:
-- {{suffix|lang||foo}} to generate "+ -foo".
-- {{suffix|lang||foo}} to generate "+ -foo".
dont_skip_items = true,
dont_skip_items = true,
-- Allow e.g. <infix> to be specified in place of <type:infix>.
pre_normalize_modifiers = pre_normalize_affix_type,
-- Don't pass in `lang` or `sc`, as they will be used as defaults to initialize the items, which we don't want
-- Don't pass in `lang` or `sc`, as they will be used as defaults to initialize the items, which we don't want
-- (particularly for `lang`), as the code in [[Module:affix]] uses the presence of `lang` as an indicator that
-- (particularly for `lang`), as the code in [[Module:affix]] uses the presence of `lang` as an indicator that
Line 107: Line 144:
if not saw_item_property then
if not saw_item_property then
items[i] = nil
items[i] = nil
elseif item.type then
-- Validate and canonicalize affix types.
if not recognized_affix_types[item.type] then
local valid_types = {}
for k in pairs(recognized_affix_types) do
insert(valid_types, ("'%s'"):format(k))
end
table.sort(recognized_affix_types)
error(("Unrecognized affix type '%s' in item %s; valid values are %s"):format(
item.type, item.itemno, table.concat(valid_types, ", ")))
else
item.type = recognized_affix_types[item.type]
end
end
end
end
if args.type and args.type.default and not m_affix.etymology_types[args.type.default] then
error("Unrecognized etymology type: '" .. args.type.default .. "'")
end
end


Line 120: Line 174:
data.lit = args.lit and args.lit.default
data.lit = args.lit and args.lit.default
data.sort_key = args.sort
data.sort_key = args.sort
data.type = args.type
data.type = args.type and args.type.default
data.nocap = args.nocap
data.nocap = args.nocap
data.notext = args.notext
data.notext = args.notext
Line 135: Line 189:
function export.affix(frame)
function export.affix(frame)
local function extra_params(params)
local function extra_params(params)
params.type = {}
params.notext = {type = "boolean"}
params.notext = {type = "boolean"}
params.nocat = {type = "boolean"}
params.nocat = {type = "boolean"}
Line 144: Line 197:
raw_args = frame:getParent().args,
raw_args = frame:getParent().args,
extra_params = extra_params,
extra_params = extra_params,
allow_type = true,
}
}
if args.type and not m_affix.etymology_types[args.type] then
error("Unrecognized etymology type: '" .. args.type .. "'")
end


-- There must be at least one part to display. If there are gaps, a term
-- There must be at least one part to display. If there are gaps, a term
-- request will be shown.
-- request will be shown.
if not next(parts) and not args.type then
if not next(parts) and not args.type.default then
if mw.title.getCurrentTitle().nsText == "Template" then
if mw.title.getCurrentTitle().nsText == "Template" then
parts = { {term = "prefix-"}, {term = "base"}, {term = "-suffix"} }
parts = { {term = "prefix-"}, {term = "base"}, {term = "-suffix"} }
Line 165: Line 215:
function export.compound(frame)
function export.compound(frame)
local function extra_params(params)
local function extra_params(params)
params.type = {}
params.notext = {type = "boolean"}
params.notext = {type = "boolean"}
params.nocat = {type = "boolean"}
params.nocat = {type = "boolean"}
Line 174: Line 223:
raw_args = frame:getParent().args,
raw_args = frame:getParent().args,
extra_params = extra_params,
extra_params = extra_params,
allow_type = true,
}
}
if args.type and not m_affix.etymology_types[args.type] then
error("Unrecognized etymology type: '" .. args.type .. "'")
end


-- There must be at least one part to display. If there are gaps, a term
-- There must be at least one part to display. If there are gaps, a term
-- request will be shown.
-- request will be shown.
if not next(parts) and not args.type then
if not next(parts) and not args.type.default then
if mw.title.getCurrentTitle().nsText == "Template" then
if mw.title.getCurrentTitle().nsText == "Template" then
parts = { {term = "first"}, {term = "second"} }
parts = { {term = "first"}, {term = "second"} }
Line 282: Line 328:


local function extra_params(params)
local function extra_params(params)
params.type = {}
params.notext = {type = "boolean"}
params.notext = {type = "boolean"}
params.nocat = {type = "boolean"}
params.nocat = {type = "boolean"}
Line 291: Line 336:
raw_args = parent_args,
raw_args = parent_args,
extra_params = extra_params,
extra_params = extra_params,
allow_type = true,
}
}
if args.type and not m_affix.etymology_types[args.type] then
error("Unrecognized etymology type: '" .. args.type .. "'")
end


-- There must be at least one part to display. If there are gaps, a term
-- There must be at least one part to display. If there are gaps, a term
Line 523: Line 565:
}
}
local derivtype = iargs.derivtype
local derivtype = iargs.derivtype
if derivtype == "PIE root" then
params[1] = {required = "true", type = "language", default = "und"}
params[1] = {}
params[2] = {}
else
params[1] = {required = "true", type = "language", default = "und"}
params[2] = {}
end


local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)


local lang
local lang = args[1]
local term
local term = args[2] or args.head
 
if derivtype == "PIE root" then
lang = m_languages.getByCode("ine-pro", true)
term = args[1] or args.head
 
if term then
term = "*" .. term .. "-"
end
else
lang = args[1]
term = args[2] or args.head
end
 
local id = args.id
local id = args.id
local sc = args.sc
local sc = args.sc
local pos = require("Module:string utilities").pluralize(args.pos or "word")
local pos = require("Module:string utilities").pluralize(args.pos or "term")


if not term then
if not term then
Line 560: Line 585:
term = SUBPAGE
term = SUBPAGE
end
end
end
if derivtype == "PIE root" then
require('Module:debug/track')('collapsible category tree/PIE root')
return require('Module:collapsible category tree').make{
category = "Terms derived from the Proto-Indo-European root " .. term .. (id and " (" .. id .. ")" or ""),
}
end
end