{JSON.stringify(res, null, " ")}diff --git a/src/lib/src/phrase-building/vp-tools.ts b/src/lib/src/phrase-building/vp-tools.ts index e7b355b..b65f16b 100644 --- a/src/lib/src/phrase-building/vp-tools.ts +++ b/src/lib/src/phrase-building/vp-tools.ts @@ -1,6 +1,10 @@ import * as T from "../../../types"; import { concatPsString, psRemove, psStringEquals } from "../p-text-helpers"; -import { isPerfectTense } from "../type-predicates"; +import { + isImperativeTense, + isPerfectTense, + isVerbTense, +} from "../type-predicates"; import * as grammarUnits from "../grammar-units"; import { isSecondPerson, randomNumber } from "../misc-helpers"; import { @@ -278,6 +282,36 @@ export function completeVPSelection( }; } +export function uncompleteVPSelection( + vps: T.VPSelectionComplete +): T.VPSelectionState { + const tense = vps.verb.tense; + const tenseCategory = isVerbTense(tense) + ? "basic" + : isPerfectTense(tense) + ? "perfect" + : isImperativeTense(tense) + ? "modal" + : "imperative"; + return { + ...vps, + verb: { + ...vps.verb, + verbTense: + tenseCategory === "basic" ? (tense as T.VerbTense) : "presentVerb", + perfectTense: + tenseCategory === "perfect" + ? (tense as T.PerfectTense) + : "presentPerfect", + imperativeTense: + tenseCategory === "imperative" + ? (tense as T.ImperativeTense) + : "imperfectiveImperative", + tenseCategory, + }, + }; +} + export function isThirdPerson(p: T.Person): boolean { return ( p === T.Person.ThirdSingMale || diff --git a/src/lib/src/type-predicates.ts b/src/lib/src/type-predicates.ts index 3c69cbc..1c1435b 100644 --- a/src/lib/src/type-predicates.ts +++ b/src/lib/src/type-predicates.ts @@ -3,6 +3,17 @@ import { pashtoConsonants } from "./pashto-consonants"; import { endsWith } from "./p-text-helpers"; import { countSyllables } from "./accent-helpers"; +const verbTenses: T.VerbTense[] = [ + "presentVerb", + "subjunctiveVerb", + "perfectiveFuture", + "imperfectiveFuture", + "perfectivePast", + "imperfectivePast", + "habitualPerfectivePast", + "habitualImperfectivePast", +]; + export function isTlulVerb(e: T.VerbEntry | T.VerbDictionaryEntry): boolean { const entry = "entry" in e ? e.entry : e; return ( @@ -276,16 +287,6 @@ export function isPerfectTense(tense: T.Tense): tense is T.PerfectTense { } export function isVerbTense(tense: T.Tense): tense is T.VerbTense { - const verbTenses: T.VerbTense[] = [ - "presentVerb", - "subjunctiveVerb", - "perfectiveFuture", - "imperfectiveFuture", - "perfectivePast", - "imperfectivePast", - "habitualPerfectivePast", - "habitualImperfectivePast", - ]; return verbTenses.some((x) => x === tense); } diff --git a/src/types.ts b/src/types.ts index ee80f26..9327976 100644 --- a/src/types.ts +++ b/src/types.ts @@ -787,7 +787,7 @@ export type VerbFormName = export type VerbSelectionComplete = Omit< VerbSelection, - "object" | "verbTense" | "perfectTense" | "imperativeTense" | "tenseCategory" + "verbTense" | "perfectTense" | "imperativeTense" | "tenseCategory" > & { tense: VerbFormName; };