48,407
edits
(Created page with "local export = {} local m_affix = require("Module:affix") local parameter_utilities_module = "Module:parameter utilities" local pseudo_loan_module = "Module:affix/pseudo-loan" local function is_property_key(k) return require(parameter_utilities_module).item_key_is_property(k) end -- Parse raw arguments. A single parameter `data` is passed in, with the following fields: -- * `raw_args`: The raw arguments to parse, normally taken from `frame:getParent().args`. -- * `...") |
No edit summary Tag: Manual revert |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
local m_affix = require("Module:affix") | local m_affix = require("Module:affix") | ||
local m_utilities = require("Module:utilities") | |||
local en_utilities_module = "Module:en-utilities" | |||
local parameter_utilities_module = "Module:parameter utilities" | local parameter_utilities_module = "Module:parameter utilities" | ||
local pseudo_loan_module = "Module:affix/pseudo-loan" | local pseudo_loan_module = "Module:affix/pseudo-loan" | ||
| Line 10: | Line 12: | ||
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 22: | Line 52: | ||
-- * `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 57: | Line 89: | ||
local m_param_utils = require(parameter_utilities_module) | local m_param_utils = require(parameter_utilities_module) | ||
local | 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 66: | Line 98: | ||
{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) | ||
end | end | ||
local items, args = m_param_utils. | local items, args = m_param_utils.parse_list_with_inline_modifiers_and_separate_params { | ||
params = params, | params = params, | ||
param_mods = param_mods, | param_mods = param_mods, | ||
| Line 81: | Line 118: | ||
-- {{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 106: | Line 145: | ||
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 119: | Line 175: | ||
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 134: | Line 190: | ||
function export.affix(frame) | function export.affix(frame) | ||
local function extra_params(params) | local function extra_params(params) | ||
params.notext = {type = "boolean"} | params.notext = {type = "boolean"} | ||
params.nocat = {type = "boolean"} | params.nocat = {type = "boolean"} | ||
| Line 143: | Line 198: | ||
raw_args = frame:getParent().args, | raw_args = frame:getParent().args, | ||
extra_params = extra_params, | extra_params = extra_params, | ||
allow_type = true, | |||
} | } | ||
-- 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 164: | Line 216: | ||
function export.compound(frame) | function export.compound(frame) | ||
local function extra_params(params) | local function extra_params(params) | ||
params.notext = {type = "boolean"} | params.notext = {type = "boolean"} | ||
params.nocat = {type = "boolean"} | params.nocat = {type = "boolean"} | ||
| Line 173: | Line 224: | ||
raw_args = frame:getParent().args, | raw_args = frame:getParent().args, | ||
extra_params = extra_params, | extra_params = extra_params, | ||
allow_type = true, | |||
} | } | ||
-- 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 281: | Line 329: | ||
local function extra_params(params) | local function extra_params(params) | ||
params.notext = {type = "boolean"} | params.notext = {type = "boolean"} | ||
params.nocat = {type = "boolean"} | params.nocat = {type = "boolean"} | ||
| Line 290: | Line 337: | ||
raw_args = parent_args, | raw_args = parent_args, | ||
extra_params = extra_params, | extra_params = extra_params, | ||
allow_type = true, | |||
} | } | ||
-- 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 512: | Line 556: | ||
local iparams = { | local iparams = { | ||
["derivtype"] = {}, | ["derivtype"] = {}, | ||
} | } | ||
local iargs = require("Module:parameters").process(frame.args, iparams) | local iargs = require("Module:parameters").process(frame.args, iparams) | ||
| Line 523: | Line 566: | ||
} | } | ||
local derivtype = iargs.derivtype | local derivtype = iargs.derivtype | ||
params[1] = {required = "true", type = "language", default = "und"} | |||
params[2] = {} | |||
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 = args[2] or args.head | |||
local id = args.id | local id = args.id | ||
local sc = args.sc | local sc = args.sc | ||
local pos = require( | local pos = require(en_utilities_module).pluralize(args.pos or "word") | ||
if not term then | if not term then | ||
| Line 560: | Line 586: | ||
term = SUBPAGE | term = SUBPAGE | ||
end | end | ||
end | end | ||
| Line 586: | Line 600: | ||
end | end | ||
return | return require('Module:collapsible category tree').make{ | ||
lang = lang, | |||
sc = sc, | |||
category = category, | |||
} | |||
end | end | ||
return export | return export | ||