Stub out expression handling
This commit is contained in:
parent
85b17d6d16
commit
ef16fefe48
3 changed files with 19 additions and 2 deletions
|
@ -1,7 +1,8 @@
|
|||
import { Card, CardVm, GetField } from "./lib/card";
|
||||
import { Expr } from "./lib/expr";
|
||||
import { ALL as HTML } from "./lib/html";
|
||||
import { parse } from "./parser";
|
||||
import { runNoctl, Vm } from "./vm";
|
||||
import { runNoctl } from "./vm";
|
||||
import { AsHtml, AsText, TextPiece } from "./words";
|
||||
|
||||
/**
|
||||
|
@ -119,7 +120,7 @@ function render() {
|
|||
|
||||
const vm: CardVm = {
|
||||
mode: "render",
|
||||
commands: { ...HTML, get: GetField },
|
||||
commands: { ...HTML, get: GetField, expr: Expr },
|
||||
output: "",
|
||||
card: theCard,
|
||||
};
|
||||
|
|
12
src/lib/expr.ts
Normal file
12
src/lib/expr.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { AsText, ProcResult, TextPiece } from "../words";
|
||||
|
||||
export function Expr({}, argv: TextPiece[]): ProcResult {
|
||||
const name = argv[0];
|
||||
if ("bare" in name && name.bare == "expr") {
|
||||
// being called as [expr ...], not fallback for math
|
||||
argv.splice(0, 1);
|
||||
}
|
||||
return {
|
||||
text: `Will do math to solve ${argv.map(AsText).join(" ")} eventually`,
|
||||
};
|
||||
}
|
|
@ -59,6 +59,8 @@ function evaluateWord<Context>(
|
|||
}
|
||||
}
|
||||
|
||||
const NUMBER = /^\d+$/;
|
||||
|
||||
/**
|
||||
* Runs a script in the context of a Noctl state. Potentially mutates the state.
|
||||
*
|
||||
|
@ -87,6 +89,8 @@ export function runNoctl<Context>(
|
|||
const name = AsText(argv[0]);
|
||||
if (name in state.commands) {
|
||||
returnWord = state.commands[name](state, argv);
|
||||
} else if (NUMBER.test(name) && "expr" in state.commands) {
|
||||
returnWord = state.commands.expr(state, argv);
|
||||
} else {
|
||||
returnWord = { error: `Unknown Command: ${name}` };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue