better VP block parsing
This commit is contained in:
parent
a9f93dc717
commit
0b5eb452e1
|
@ -22,31 +22,31 @@ export function parseBlocks(
|
||||||
if (tokens.length === 0) {
|
if (tokens.length === 0) {
|
||||||
return returnParseResult(tokens, { blocks, kids });
|
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(
|
const prevPh: T.ParsedPH | undefined = blocks.find(
|
||||||
(b): b is T.ParsedPH => b.type === "PH"
|
(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>[] = [
|
const allBlocks: T.ParseResult<T.ParsedBlock | T.ParsedKidsSection>[] = [
|
||||||
...(prevPh ? [] : parseAP(tokens, lookup)),
|
...(inPreVerbSection
|
||||||
...(prevPh ? [] : parseNP(tokens, lookup)),
|
? [...parseAP(tokens, lookup), ...parseNP(tokens, lookup)]
|
||||||
...(vbExists || prevPh ? [] : parsePH(tokens)),
|
: []),
|
||||||
...parseVerb(tokens, lookup),
|
// ensure at most one of each PH, VBE, VBP
|
||||||
...parsePastPart(tokens, lookup),
|
...(prevPh ? [] : parsePH(tokens)),
|
||||||
...parseEquative(tokens),
|
...(blocks.some(isParsedVBE)
|
||||||
...parseNeg(tokens),
|
? []
|
||||||
|
: [...parseVerb(tokens, lookup), ...parseEquative(tokens)]),
|
||||||
|
...(blocks.some(isParsedVBP) ? [] : parsePastPart(tokens, lookup)),
|
||||||
|
...(blocks.some((b) => b.type === "negative") ? [] : parseNeg(tokens)),
|
||||||
...parseKidsSection(tokens, []),
|
...parseKidsSection(tokens, []),
|
||||||
];
|
];
|
||||||
// TODO: is this necessary?
|
const allResults = [...allBlocks, ...parseKidsSection(tokens, [])];
|
||||||
// if (!allResults.length) {
|
|
||||||
// return [
|
|
||||||
// {
|
|
||||||
// tokens,
|
|
||||||
// body: { blocks, kids },
|
|
||||||
// errors: [],
|
|
||||||
// },
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
return bindParseResult(allResults, (tokens, r) => {
|
return bindParseResult(allResults, (tokens, r) => {
|
||||||
const errors: T.ParseError[] = [];
|
const errors: T.ParseError[] = [];
|
||||||
if (r.type === "kids") {
|
if (r.type === "kids") {
|
||||||
|
@ -108,3 +108,17 @@ function getPhFromVerb(v: T.VerbEntry, base: "root" | "stem"): string {
|
||||||
}
|
}
|
||||||
return "و";
|
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")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import { equals } from "rambda";
|
||||||
// learn to use jq to edit selected json in vim ?? COOOL
|
// learn to use jq to edit selected json in vim ?? COOOL
|
||||||
|
|
||||||
// TODO: test grammatically transitive stuff
|
// TODO: test grammatically transitive stuff
|
||||||
// test bo ba ye dzee
|
|
||||||
// test raaba ye wree
|
// test raaba ye wree
|
||||||
|
|
||||||
// TODO: somehow make sure ALL BLOCKS ARE USED UP
|
// 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
|
// TODO: way to get an error message for past participle and equative
|
||||||
// not matching up
|
// not matching up
|
||||||
|
|
||||||
|
// TODO: negative with perfect forms
|
||||||
|
|
||||||
export function parseVP(
|
export function parseVP(
|
||||||
tokens: Readonly<T.Token[]>,
|
tokens: Readonly<T.Token[]>,
|
||||||
lookup: LookupFunction
|
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({
|
function negativeInPlace({
|
||||||
neg,
|
neg,
|
||||||
v,
|
v,
|
||||||
|
|
Loading…
Reference in New Issue