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:
@ -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,
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user