@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.
48 lines (47 loc) • 1.62 kB
TypeScript
import { type PartialFormative, type PartialNominalFormative, type Word } from "../generate/index.js";
/** A result type showing either success or failure. */
export type Result<T> = {
readonly ok: true;
readonly value: T;
} | {
readonly ok: false;
readonly reason: string;
};
/**
* A helper type which removes properties that may only be undefined from an
* object type `T`.
*/
export type OmitUndefinedValues<T> = T extends infer U ? {
[K in keyof U as [U[K]] extends [undefined] ? never : K]: U[K];
} : never;
/** A parsed item from a string of sentences. */
export type ParsedItem = {
readonly type: "word";
readonly word: Word;
readonly source: string;
readonly properNoun?: string | undefined;
} | {
readonly type: "chain";
readonly words: readonly [
readonly [source: string, formative: PartialNominalFormative],
...(readonly [source: string, formative: PartialNominalFormative])[],
readonly [source: string, formative: PartialFormative]
];
readonly properNoun?: string | undefined;
} | {
readonly type: "brokenChain";
readonly words: readonly [
readonly [source: string, formative: PartialNominalFormative],
...(readonly [source: string, formative: PartialNominalFormative])[]
];
readonly properNoun?: undefined;
} | {
readonly type: "sentenceBreak";
};
/**
* Parses romanized Ithkuilic text into a series of items.
*
* @param text The text to be parsed.
* @returns A `Result` containing an array of `ParsedItem`s.
*/
export declare function parseSentences(text: string): Result<ParsedItem[]>;