https://linguifex.com/w/index.php?title=Module:form_of/functions&feed=atom&action=history
Module:form of/functions - Revision history
2024-03-29T12:03:17Z
Revision history for this page on the wiki
MediaWiki 1.39.1
https://linguifex.com/w/index.php?title=Module:form_of/functions&diff=225089&oldid=prev
Sware at 19:38, 22 March 2021
2021-03-22T19:38:09Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:38, 22 March 2021</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l27">Line 27:</td>
<td colspan="2" class="diff-lineno">Line 27:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function wrap_in_inflection_of_sep(text)</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function wrap_in_inflection_of_sep(text)</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> return '<span <del style="font-weight: bold; text-decoration: none;">class="inflection-of-sep"</del>>' .. text .. '</span>'</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> return '<span>' .. text .. '</span>'</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l42">Line 42:</td>
<td colspan="2" class="diff-lineno">Line 42:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return seq[1] .. wrap_in_inflection_of_sep("&#32;and&#32;") .. seq[2]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return seq[1] .. wrap_in_inflection_of_sep("&#32;and&#32;") .. seq[2]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> local comma = '<span <del style="font-weight: bold; text-decoration: none;">class="serial-comma"</del>>,</span>'</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local comma = '<span>,</span>'</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> local conj = '<span <del style="font-weight: bold; text-decoration: none;">class="serial-and"</del>>&#32;and&#32;</span>'</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local conj = '<span>&#32;and&#32;</span>'</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return table.concat(seq, wrap_in_inflection_of_sep(",&#32;"), 1, length - 1) ..</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return table.concat(seq, wrap_in_inflection_of_sep(",&#32;"), 1, length - 1) ..</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> wrap_in_inflection_of_sep(comma .. conj) .. seq[length]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> wrap_in_inflection_of_sep(comma .. conj) .. seq[length]</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l72">Line 72:</td>
<td colspan="2" class="diff-lineno">Line 72:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> error("Unrecognized multipart join strategy: " .. strategy)</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> error("Unrecognized multipart join strategy: " .. strategy)</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> return '<span <del style="font-weight: bold; text-decoration: none;">class="inflection-of-conjoined"</del>>' .. retval .. '</span>'</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> return '<span>' .. retval .. '</span>'</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
</table>
Sware
https://linguifex.com/w/index.php?title=Module:form_of/functions&diff=222861&oldid=prev
Sware: Created page with "--[=[ DISPLAY_HANDLERS is a list of one or more functions that provide special handling for multipart tags. Each function takes formerly a single argument (the multipart tag),..."
2021-03-18T12:55:01Z
<p>Created page with "--[=[ DISPLAY_HANDLERS is a list of one or more functions that provide special handling for multipart tags. Each function takes formerly a single argument (the multipart tag),..."</p>
<p><b>New page</b></p><div>--[=[<br />
DISPLAY_HANDLERS is a list of one or more functions that provide special<br />
handling for multipart tags. Each function takes formerly a single argument<br />
(the multipart tag), now temporarily two arguments (the multipart tag and<br />
the join strategy, which can be nil to use the default), and should either<br />
return the formatted display text or nil to check the next handler. If no<br />
handlers apply, there is a default handler that appropriately formats most<br />
multipart tags.<br />
<br />
CAT_FUNCTIONS is a map from function names to functions of a single argument,<br />
as described in [[Module:form of/cats]]. There are two types of functions:<br />
condition handlers (which return true or false) and spec handlers (which<br />
return a specification, as described in [[Module:form of/cats]]). We need to<br />
put the functions here rather than in [[Module:form of/cats]] because that<br />
module is loaded using mw.loadData(), which can't directly handle functions.<br />
]=]<br />
<br />
local export = {}<br />
<br />
function export.multipart_join_strategy()<br />
-- Recognized values:<br />
-- "and": Join with "and", using commas for 3 or more items<br />
-- "en-dash": Join with – (en-dash)<br />
-- "slash": Join with / (slash)<br />
return "slash"<br />
end<br />
<br />
local function wrap_in_inflection_of_sep(text)<br />
return '<span class="inflection-of-sep">' .. text .. '</span>'<br />
end<br />
<br />
-- This is a local version of serialCommaJoin from [[Module:table]] that<br />
-- implements it a bit differently.<br />
local function join_multiparts_with_serial_comma(seq)<br />
local length = #seq<br />
<br />
if length == 0 then<br />
return ""<br />
elseif length == 1 then<br />
return seq[1] -- nothing to join<br />
elseif length == 2 then<br />
return seq[1] .. wrap_in_inflection_of_sep("&#32;and&#32;") .. seq[2]<br />
else<br />
local comma = '<span class="serial-comma">,</span>'<br />
local conj = '<span class="serial-and">&#32;and&#32;</span>'<br />
return table.concat(seq, wrap_in_inflection_of_sep(",&#32;"), 1, length - 1) ..<br />
wrap_in_inflection_of_sep(comma .. conj) .. seq[length]<br />
end<br />
end<br />
<br />
function export.join_multiparts(parts, joiner)<br />
-- Display the elements of a multipart tag. Currently we use "and",<br />
-- with commas when then are three or more elements, of the form<br />
-- "foo, bar, baz and bat"; but we are seriously considering switching<br />
-- to en-dash, e.g. "foo–bar–baz–bat". Arguably,<br />
-- dative–ablative masculine–feminine–neuter plural<br />
-- looks better then<br />
-- dative and ablative masculine, feminine and neuter plural<br />
-- and<br />
-- first–second–third-person singular present subjunctive<br />
-- looks better than<br />
-- first-, second- and third-person singular present subjunctive<br />
local strategy = joiner or export.multipart_join_strategy()<br />
local retval<br />
if strategy == "and" then<br />
retval = join_multiparts_with_serial_comma(parts)<br />
elseif strategy == "en-dash" then<br />
retval = table.concat(parts, wrap_in_inflection_of_sep("–"))<br />
elseif strategy == "slash" then<br />
retval = table.concat(parts, wrap_in_inflection_of_sep("/"))<br />
else<br />
error("Unrecognized multipart join strategy: " .. strategy)<br />
end<br />
return '<span class="inflection-of-conjoined">' .. retval .. '</span>'<br />
end<br />
<br />
export.cat_functions = {}<br />
<br />
export.display_handlers = {}<br />
<br />
-- Display handler to clean up display of multiple persons by omitting<br />
-- redundant "person" in all but the last element. For example, the tag<br />
-- "123" maps to "1//2//3", which in turn gets displayed as (approximately)<br />
-- "first-, second- and third-person" (with appropriate glossary links, and<br />
-- appropriate spans marking the serial comma).<br />
table.insert(export.display_handlers,<br />
function(tags, joiner)<br />
local els = {}<br />
local numtags = #tags<br />
local strategy = joiner or export.multipart_join_strategy()<br />
for i, tag in ipairs(tags) do<br />
local suffix = i == numtags and "-person]]" or<br />
strategy == "and" and "-]]" or "]]"<br />
if tag == "first-person" then<br />
table.insert(els, "[[Appendix:Glossary#first person|first" .. suffix)<br />
elseif tag == "second-person" then<br />
table.insert(els, "[[Appendix:Glossary#second person|second" .. suffix)<br />
elseif tag == "third-person" then<br />
table.insert(els, "[[Appendix:Glossary#third person|third" .. suffix)<br />
else<br />
return nil<br />
end<br />
end<br />
return export.join_multiparts(els, joiner)<br />
end<br />
)<br />
<br />
return export<br />
<br />
-- For Vim, so we get 4-space tabs<br />
-- vim: set ts=4 sw=4 noet:</div>
Sware