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

@ -11,16 +11,13 @@ import * as R from "./regex";
import * as C from "../types";
/**
* Ideally, this would convert past form of verb to present form. Due to
* the requirement of an English dictionary for sufficient accuracy, we instead
* require the past form to be the same as present form in Esolang Park. Thus,
* this function is currently a no-op.
* Converts a verb to the past tense version of it
*
* @param verbed Past form of verb
* @returns Present imperative form of verb
* @param verb Present form of verb
* @returns Past form of verb
*/
const toPresentTense = (verbed: string) => {
return verbed;
export const toPastTense = (verb: string) => {
return verb.endsWith('e') ? verb + "d" : verb + "ed"
};
/** Parse a string as an ingredient measure */
@ -219,7 +216,7 @@ export const parseMethodStep = (line: string): C.ChefOperation => {
// `Verb` [the `ingredient`] until `verbed`
const matches = assertMatch(line, R.LoopEnderRegex);
const ingredient = matches[1] || undefined;
const verb = toPresentTense(matches[2]);
const verb = matches[2];
return {
code: "LOOP-CLOSE",
ing: ingredient,

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;