Chef: Heuristic for verb past tense conversion

Add a heuristic method for converting verb to past tense by appending d/ed to end of the present tense form.
This commit is contained in:
Seggan
2024-03-28 13:22:46 -04:00
committed by GitHub
parent 78996f849d
commit 12a318dcbd
5 changed files with 22 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
import * as T from "../types";
import { DocumentRange } from "../../types";
import { parseIngredientItem, parseMethodStep } from "./core";
import { parseIngredientItem, parseMethodStep, toPastTense } from "./core";
import { ParseError } from "../../worker-errors";
import { isSyntaxError, SyntaxError } from "../constants";
@@ -193,10 +193,14 @@ const processMethodSegment = (
case "LOOP-CLOSE": {
// Validate match with innermost loop
const loop = loopStack.pop()!;
if (loop.verb !== op.verb)
const loop = loopStack.pop();
if (!loop) {
throw new SyntaxError("No loop opener found");
}
const past = toPastTense(loop.verb);
if (past !== op.verb)
throw new SyntaxError(
`Loop verb mismatch: expected '${loop.verb}', found '${op.verb}'`
`Loop verb mismatch: expected '${past}', found '${op.verb}'`
);
op.opener = loop.opener;