diff --git a/src/lib/src/parsing/parse-blocks.ts b/src/lib/src/parsing/parse-blocks.ts index a721103..efe2423 100644 --- a/src/lib/src/parsing/parse-blocks.ts +++ b/src/lib/src/parsing/parse-blocks.ts @@ -22,31 +22,31 @@ export function parseBlocks( if (tokens.length === 0) { return returnParseResult(tokens, { blocks, kids }); } + const inPreVerbSection = blocks.every( + (b) => + b.type !== "PH" && + b.type !== "VB" && + b.type !== "welded" && + b.type !== "negative" + ); const prevPh: T.ParsedPH | undefined = blocks.find( (b): b is T.ParsedPH => b.type === "PH" ); - const vbExists = blocks.some((b) => "type" in b && b.type === "VB"); - const allResults: T.ParseResult[] = [ - ...(prevPh ? [] : parseAP(tokens, lookup)), - ...(prevPh ? [] : parseNP(tokens, lookup)), - ...(vbExists || prevPh ? [] : parsePH(tokens)), - ...parseVerb(tokens, lookup), - ...parsePastPart(tokens, lookup), - ...parseEquative(tokens), - ...parseNeg(tokens), + const allBlocks: T.ParseResult[] = [ + ...(inPreVerbSection + ? [...parseAP(tokens, lookup), ...parseNP(tokens, lookup)] + : []), + // ensure at most one of each PH, VBE, VBP + ...(prevPh ? [] : parsePH(tokens)), + ...(blocks.some(isParsedVBE) + ? [] + : [...parseVerb(tokens, lookup), ...parseEquative(tokens)]), + ...(blocks.some(isParsedVBP) ? [] : parsePastPart(tokens, lookup)), + ...(blocks.some((b) => b.type === "negative") ? [] : parseNeg(tokens)), ...parseKidsSection(tokens, []), ]; - // TODO: is this necessary? - // if (!allResults.length) { - // return [ - // { - // tokens, - // body: { blocks, kids }, - // errors: [], - // }, - // ]; - // } + const allResults = [...allBlocks, ...parseKidsSection(tokens, [])]; return bindParseResult(allResults, (tokens, r) => { const errors: T.ParseError[] = []; if (r.type === "kids") { @@ -108,3 +108,17 @@ function getPhFromVerb(v: T.VerbEntry, base: "root" | "stem"): string { } return "و"; } + +function isParsedVBP(b: T.ParsedBlock): boolean { + return ( + (b.type === "VB" || b.type === "welded") && + (b.info.type === "ability" || b.info.type === "ppart") + ); +} + +function isParsedVBE(b: T.ParsedBlock): boolean { + return ( + (b.type === "VB" || b.type === "welded") && + (b.info.type === "verb" || b.info.type === "equative") + ); +} diff --git a/src/lib/src/parsing/parse-vp.ts b/src/lib/src/parsing/parse-vp.ts index ef2d966..41bc64c 100644 --- a/src/lib/src/parsing/parse-vp.ts +++ b/src/lib/src/parsing/parse-vp.ts @@ -23,7 +23,6 @@ import { equals } from "rambda"; // learn to use jq to edit selected json in vim ?? COOOL // TODO: test grammatically transitive stuff -// test bo ba ye dzee // test raaba ye wree // TODO: somehow make sure ALL BLOCKS ARE USED UP @@ -33,6 +32,8 @@ import { equals } from "rambda"; // TODO: way to get an error message for past participle and equative // not matching up +// TODO: negative with perfect forms + export function parseVP( tokens: Readonly, lookup: LookupFunction @@ -894,6 +895,15 @@ function getTenseFromRootsStems( } } +// possible neg setups +// NEG VBE +// PH NEG VBE +// NEG (Non-و PH) VBE + +// (PH) NEG VBE VBP +// (PH) VBP NEG VBE +// (with non-و negative things?) + function negativeInPlace({ neg, v,