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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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;

View File

@ -355,14 +355,14 @@ describe("Parsing method instructions", () => {
});
test("`Verb` [the `ingredient`] until `verbed`", () => {
testMethodOp("Destroy until bake", {
testMethodOp("Destroy until baked", {
code: "LOOP-CLOSE",
verb: "bake",
verb: "baked",
opener: JumpAddressPlaceholder,
});
testMethodOp("Destroy the tomato ketchup until bake", {
testMethodOp("Destroy the tomato ketchup until baked", {
code: "LOOP-CLOSE",
verb: "bake",
verb: "baked",
ing: "tomato ketchup",
opener: JumpAddressPlaceholder,
});

View File

@ -18,14 +18,14 @@ Fold numbers into 2nd mixing bowl.
Put numbers into 2nd mixing bowl.
Calculate the numbers.
Serve with salt and pepper.
Ponder the numbers until calculate.
Ponder the numbers until calculated.
Add cheese to 2nd mixing bowl.
Add cheese to 2nd mixing bowl.
Fold numbers into 2nd mixing bowl.
Move the numbers.
Fold cheese into mixing bowl.
Put cheese into 2nd mixing bowl.
Transfer the numbers until move.
Transfer the numbers until moved.
Pour contents of the 2nd mixing bowl into the baking dish.
Serves 1.

View File

@ -38,7 +38,7 @@ Stir the mixing bowl for 4 minutes.
Liquefy the contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.
bake the cake mixture.
Wait until bake.
Wait until baked.
Serve with chocolate sauce.
chocolate sauce.
@ -56,7 +56,7 @@ Put sugar into the mixing bowl.
Put hot water into the mixing bowl.
Put heated double cream into the mixing bowl.
dissolve the sugar.
agitate the sugar until dissolve.
agitate the sugar until dissolved.
Liquefy the dark chocolate.
Put dark chocolate into the mixing bowl.
Liquefy the milk chocolate.