en:Module:Wd 2017年5月7日 (日) 16:15(UTC)より
template>K-iczn (en:Module:Wd 2017年5月7日 (日) 16:15(UTC)より) |
template>K-iczn (en:Module:Wd 2017年5月7日 (日) 16:15(UTC)より) |
||
48行目: | 48行目: | ||
} | } | ||
-- default value objects, should NOT be mutated but instead copied | |||
local defaultSeparators = { | local defaultSeparators = { | ||
["sep"] = " " | ["sep"] = {" "}, | ||
["sep%s"] = "," | ["sep%s"] = {","}, | ||
["sep%q"] = "; " | ["sep%q"] = {"; "}, | ||
["sep%q\\d"] = ", " | ["sep%q\\d"] = {", "}, | ||
["sep%r"] = | ["sep%r"] = nil, -- none | ||
["punc"] = | ["punc"] = nil -- none | ||
} | } | ||
66行目: | 67行目: | ||
cfg.separators = { | cfg.separators = { | ||
-- | -- single value objects wrapped in arrays so that we can pass by reference | ||
["sep"] = {defaultSeparators["sep"]}, | ["sep"] = {copyTable(defaultSeparators["sep"])}, | ||
["sep%s"] = {defaultSeparators["sep%s"]}, | ["sep%s"] = {copyTable(defaultSeparators["sep%s"])}, | ||
["sep%q"] = {defaultSeparators["sep%q"]}, | ["sep%q"] = {copyTable(defaultSeparators["sep%q"])}, | ||
["sep%r"] = {defaultSeparators["sep%r"]}, | ["sep%r"] = {copyTable(defaultSeparators["sep%r"])}, | ||
["punc"] = {defaultSeparators["punc"]} | ["punc"] = {copyTable(defaultSeparators["punc"])} | ||
} | } | ||
139行目: | 140行目: | ||
end | end | ||
-- used to make frame.args mutable | -- used to make frame.args mutable, to replace #frame.args (which is always 0) | ||
-- with the actual amount and to simply copy tables | |||
function copyTable(tIn) | function copyTable(tIn) | ||
if not tIn then | |||
return nil | |||
end | |||
local tOut = {} | local tOut = {} | ||
1,047行目: | 1,053行目: | ||
if self.curState == self.states[parameters.reference] then | if self.curState == self.states[parameters.reference] then | ||
-- raw reference values end with periods and require a separator | -- raw reference values end with periods and require a separator (other than none) | ||
self.separators["sep%r"][1] = " " | self.separators["sep%r"][1] = {" "} | ||
end | end | ||
1,086行目: | 1,092行目: | ||
self.states.qualifiersCount = self.states.qualifiersCount + 1 | self.states.qualifiersCount = self.states.qualifiersCount + 1 | ||
param = parameters.qualifier .. self.states.qualifiersCount | param = parameters.qualifier .. self.states.qualifiersCount | ||
self.separators["sep"..param] = {defaultSeparators["sep%q\\d"]} | self.separators["sep"..param] = {copyTable(defaultSeparators["sep%q\\d"])} | ||
elseif flag:match('^reference[s]?$') then | elseif flag:match('^reference[s]?$') then | ||
param = parameters.reference | param = parameters.reference | ||
1,208行目: | 1,214行目: | ||
local result -- collection of arrays with value objects | local result -- collection of arrays with value objects | ||
local valuesArray -- array with value objects | local valuesArray -- array with value objects | ||
local sep = | local sep = nil -- value object | ||
local out = {} -- array with value objects | local out = {} -- array with value objects | ||
1,244行目: | 1,250行目: | ||
if #out > 0 then | if #out > 0 then | ||
sep = self.separator[1] -- fixed separator | sep = self.separator[1] -- fixed separator | ||
result[parameters.separator] = | result[parameters.separator] = {self.movSeparator[1]} -- movable separator | ||
else | else | ||
sep = | sep = nil | ||
result[parameters.separator] = | result[parameters.separator] = {self.puncMark[1]} -- optional punctuation mark | ||
end | end | ||
1,253行目: | 1,259行目: | ||
if #valuesArray > 0 then | if #valuesArray > 0 then | ||
if sep | if sep then | ||
valuesArray[#valuesArray + 1] = | valuesArray[#valuesArray + 1] = sep | ||
end | end | ||
1,306行目: | 1,312行目: | ||
function State:getAllQualifiers(claim, param, result, hooks) | function State:getAllQualifiers(claim, param, result, hooks) | ||
local out = {} -- array with value objects | local out = {} -- array with value objects | ||
local sep = self.conf.separators["sep"..parameters.qualifier][1] | local sep = self.conf.separators["sep"..parameters.qualifier][1] -- value object | ||
-- iterate through the output of the separate "qualifier(s)" commands | -- iterate through the output of the separate "qualifier(s)" commands | ||
1,320行目: | 1,326行目: | ||
-- if there is already some output, then add the separator | -- if there is already some output, then add the separator | ||
if #out > 0 and sep | if #out > 0 and sep then | ||
out[#out + 1] = | out[#out + 1] = sep | ||
end | end | ||
1,584行目: | 1,590行目: | ||
_:processFlagOrCommand(funcName) -- process first command (== function name) | _:processFlagOrCommand(funcName) -- process first command (== function name) | ||
local parsedFormat, formatParams, claims | local parsedFormat, formatParams, claims, sep | ||
local hooks = {count = 0} | local hooks = {count = 0} | ||
1,662行目: | 1,668行目: | ||
-- parse the desired format, or choose an appropriate format | -- parse the desired format, or choose an appropriate format | ||
if args["format"] then | if args["format"] then | ||
parsedFormat, formatParams = parseFormat(mw.text.trim(args["format"])) | parsedFormat, formatParams = parseFormat(replaceHTMLSpaces(mw.text.trim(args["format"]))) | ||
elseif _.states.qualifiersCount > 0 then -- "qualifier(s)" command given | elseif _.states.qualifiersCount > 0 then -- "qualifier(s)" command given | ||
if _.states[parameters.property] then -- "propert(y|ies)" command given | if _.states[parameters.property] then -- "propert(y|ies)" command given | ||
1,677行目: | 1,683行目: | ||
-- if a "qualifier(s)" command and no "propert(y|ies)" command has been given, make the movable separator a semicolon | -- if a "qualifier(s)" command and no "propert(y|ies)" command has been given, make the movable separator a semicolon | ||
if _.states.qualifiersCount > 0 and not _.states[parameters.property] then | if _.states.qualifiersCount > 0 and not _.states[parameters.property] then | ||
_.separators["sep"..parameters.separator][1] = ";" | _.separators["sep"..parameters.separator][1] = {";"} | ||
end | end | ||
-- if only "reference(s)" has been given, | -- if only "reference(s)" has been given, set the default separator to none (except when raw) | ||
if _.states[parameters.reference] and not _.states[parameters.property] and _.states.qualifiersCount == 0 | if _.states[parameters.reference] and not _.states[parameters.property] and _.states.qualifiersCount == 0 | ||
and not _.states[parameters.reference].rawValue then | and not _.states[parameters.reference].rawValue then | ||
_.separators["sep"][1] = | _.separators["sep"][1] = nil | ||
end | end | ||
-- if exactly one "qualifier(s)" command has been given, make "sep%q" point to "sep%q1" to make them equivalent | -- if exactly one "qualifier(s)" command has been given, make "sep%q" point to "sep%q1" to make them equivalent; | ||
-- must come BEFORE overriding the separator values | -- must come BEFORE overriding the separator values | ||
if _.states.qualifiersCount == 1 then | if _.states.qualifiersCount == 1 then | ||
1,696行目: | 1,702行目: | ||
for i, v in pairs(_.separators) do | for i, v in pairs(_.separators) do | ||
if args[i] then | if args[i] then | ||
_.separators[i][1] = | sep = replaceHTMLSpaces(mw.text.trim(args[i])) | ||
if sep ~= "" then | |||
_.separators[i][1] = {sep} | |||
else | |||
_.separators[i][1] = nil | |||
end | |||
end | end | ||
end | end |