better VP block parsing

This commit is contained in:
adueck 2023-09-08 12:33:08 -05:00
parent a9f93dc717
commit 0b5eb452e1
2 changed files with 44 additions and 20 deletions

View File

@ -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<T.ParsedBlock | T.ParsedKidsSection>[] = [
...(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<T.ParsedBlock | T.ParsedKidsSection>[] = [
...(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")
);
}

View File

@ -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<T.Token[]>,
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,