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.

57 lines (56 loc) 1.65 kB
import { ALL_ASPECTS, ALL_EFFECTS, ALL_LEVELS, ALL_PHASES, ALL_VALENCES, } from "../../generate/formative/slot-8/index.js"; import { DCLeaf } from "../decompose.js"; import { VowelForm } from "../vowel-form.js"; const NON_ASPECTUAL_VNS = [ undefined, ALL_VALENCES, ALL_PHASES, ALL_EFFECTS, ALL_LEVELS, ]; /** * Parses a Vn form as a non-aspect. * * @param vn The Vn form to be parsed. * @returns The parsed Vn form. */ export function parseNonAspectualVn(vn) { if (vn.degree == 0) { throw new Error("Invalid Vn form: '" + vn + "'."); } return NON_ASPECTUAL_VNS[vn.sequence][vn.degree - 1]; } /** * Parses a Vn form as an Aspect. * * @param vn The Vn form to be parsed. * @returns The parsed Vn form. */ export function parseAspect(vn) { if (vn.degree == 0) { throw new Error("Invalid Vn form: '" + vn + "'."); } return ALL_ASPECTS[(vn.sequence - 1) * 9 + (vn.degree - 1)]; } /** * Decomposes a Vn form as an Aspect. * * @param vn The Vn form to be parsed. * @returns The decomposed Vn form. */ export function dcAspect(source) { return new DCLeaf(source, "Vn", "aspect", parseAspect(VowelForm.parseOrThrow(source))); } /** * Decomposes a Vn form as a non-aspect. * * @param vn The Vn form to be parsed. * @returns The decomposed Vn form. */ export function dcNonAspectualVn(source) { const vn = VowelForm.parseOrThrow(source); if (vn.degree == 0) { throw new Error("Invalid Vn form: '" + vn + "'."); } return new DCLeaf(source, "Vn", ["", "valence", "phase", "effect", "level"][vn.sequence], NON_ASPECTUAL_VNS[vn.sequence][vn.degree - 1]); }