UNPKG

@zsnout/ithkuil

Version:

A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.

66 lines (65 loc) 1.85 kB
import { parseAffix } from "../formative/affix.js"; import { multipleAffixAffixualAdjunct } from "../lex/adjunct/multiple-affix.js"; import { VowelForm } from "../vowel-form.js"; const AFFIX_REGEX = /([aeiouäëöü']+)([^aeiouäëöü']+)/g; function parseAffixes(text) { if (text == "") { return []; } const output = []; let match; while ((match = AFFIX_REGEX.exec(text))) { output.push(parseAffix(VowelForm.parseOrThrow(match[1]), match[2], false)); } return output; } const CZ_TO_SCOPE_MAP = { h: "V:DOM", "'h": "V:SUB", "'hl": "VII:DOM", "'hr": "VII:SUB", hw: "FORMATIVE", "'hw": "ADJACENT", }; const VZ_TO_SCOPE_MAP = { undefined: undefined, a: "V:DOM", u: "V:SUB", e: "VII:DOM", i: "VII:SUB", o: "FORMATIVE", ö: "ADJACENT", ai: undefined, }; /** * Builds a multiple-affix affixual adjunct. * * @param word The word to be built. * @param stress The stress of the adjunct. * @returns Either a parsed `AffixualAdjunct` indicating a success, or * `undefined` indicating a tokenization failure. Throws if the adjunct was * successfully tokenized but had another error in it (e.g. invalid Cs slot, * etc.). */ export function buildMultipleAffixAffixualAdjunct(word, stress) { const match = multipleAffixAffixualAdjunct.exec(word); if (!match) { return; } const vx = VowelForm.parseOrThrow((match[2] || match[4])); let cz; if (match[2]) { cz = "'" + match[3]; } else { cz = match[5]; } const affixes = parseAffixes(match[6]); affixes.unshift(parseAffix(vx, match[1], false)); return { affixes: affixes, scope: CZ_TO_SCOPE_MAP[cz], scope2: VZ_TO_SCOPE_MAP[match[7]], appliesToConcatenatedStemOnly: stress == "ultimate", }; }