Module:gmh-common
Jump to navigation
Jump to search
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local lang = require("Module:languages").getByCode("gmh")
local m_links = require("Module:links")
local m_table = require("Module:table")
local m_string_utilities = require("Module:string utilities")
local u = mw.ustring.char
local rsplit = mw.text.split
local rfind = mw.ustring.find
local rmatch = mw.ustring.match
local rsubn = mw.ustring.gsub
local ulen = mw.ustring.len
local uupper = mw.ustring.upper
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
-- version of rsubn() that returns a 2nd argument boolean indicating whether
-- a substitution was made.
local function rsubb(term, foo, bar)
local retval, nsubs = rsubn(term, foo, bar)
return retval, nsubs > 0
end
export.TEMP_CH = u(0xFFF0) -- used to substitute ch temporarily in the default-reducible code
export.TEMP_SOFT_LABIAL = u(0xFFF1)
local lc_vowel = "aeiouāēīōūäëöüæœâêîôû"
local uc_vowel = uupper(lc_vowel)
export.vowel = lc_vowel .. uc_vowel
export.vowel_c = "[" .. export.vowel .. "]"
export.non_vowel_c = "[^" .. export.vowel .. "]"
local lc_cons = "bpmwvdtzsȥnrlckghfjqx"
local uc_cons = uupper(lc_cons)
export.cons = lc_cons .. uc_cons
export.cons_c = "[" .. export.cons .. "]"
export.lowercase = lc_vowel .. lc_cons
export.lowercase_c = "[" .. export.lowercase .. "]"
export.uppercase = uc_vowel .. uc_cons
export.uppercase_c = "[" .. export.uppercase .. "]"
function export.apply_vowel_alternation(alt, stem)
local modstem, origvowel
if alt == "quant" then
modstem = rsub(stem, "(.*)([aouāōū])(" .. export.cons_c .. "*)$",
function(pre, vowel, post)
origvowel = vowel
if vowel == "a" then
return pre .. "e" .. post
elseif vowel == "o" then
return pre .. "ö" .. post
elseif vowel == "u" then
return pre .. "ü" .. post
elseif vowel == "ā" then
return pre .. "æ" .. post
elseif vowel == "ō" then
return pre .. "œ" .. post
else
return pre .. "iu" .. post
end
end
)
modstem = rsub(modstem, "oü(" .. export.cons_c .. "*)$", "öu%1")
modstem = rsub(modstem, "uö(" .. export.cons_c .. "*)$", "üe%1")
else
return stem
end
return modstem, origvowel
end
local function make_try(word)
return function(from, to)
local stem = rmatch(word, "^(.*)" .. from .. "$")
if stem then
return stem .. to
end
return nil
end
end
function export.secondary_umlaut(word)
local try = make_try(word)
return
try("aht", "äht") or
try("ahs", "ähs") or
word
end
function export.combine_stem_ending(base, slot, stem, ending)
if stem == "?" then
return "?"
else
stem, ending = stem, ending
if base.all_uppercase then
stem = uupper(stem)
end
return stem .. ending
end
end
return export