Skip to content

Commit

Permalink
chore,wip: partially decouple parser system
Browse files Browse the repository at this point in the history
  • Loading branch information
iyxan23 committed Sep 23, 2024
1 parent 0a37bf2 commit 66f5f12
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 220 deletions.
24 changes: 12 additions & 12 deletions src/sheet/expression/evaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";
import { callLambda, createTemplaterFunction } from "../templater-function";
import { createTemplaterNoArgsFunction } from "../templater-function";
import { evaluateExpression, Issue } from "./evaluate";
import { Expression } from "./parser";
import { BasicExpression } from "./parser";
import { success } from "./result";

function mockWarn() {
Expand All @@ -14,7 +14,7 @@ describe("expression evaluation", () => {
const consoleWarnMock = mockWarn();
test.onTestFinished(() => consoleWarnMock.mockRestore());

const expr: Expression = {
const expr: BasicExpression = {
type: "variableAccess",
identifier: "hello",
args: [],
Expand All @@ -40,7 +40,7 @@ describe("expression evaluation", () => {
const consoleWarnMock = mockWarn();
test.onTestFinished(() => consoleWarnMock.mockRestore());

const expr: Expression = {
const expr: BasicExpression = {
type: "call",
identifier: "hello",
args: ["world"],
Expand Down Expand Up @@ -70,7 +70,7 @@ describe("expression evaluation", () => {
const consoleWarnMock = mockWarn();
test.onTestFinished(() => consoleWarnMock.mockRestore());

const expr: Expression = {
const expr: BasicExpression = {
type: "blockStart",
identifier: "hello",
args: [],
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("expression evaluation", () => {
const consoleWarnMock = mockWarn();
test.onTestFinished(() => consoleWarnMock.mockRestore());

const expr: Expression = {
const expr: BasicExpression = {
type: "blockEnd",
identifier: "hello",
};
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("expression evaluation", () => {
const consoleWarnMock = mockWarn();
test.onTestFinished(() => consoleWarnMock.mockRestore());

const expr: Expression = {
const expr: BasicExpression = {
type: "variableHoist",
identifier: "hello",
expression: { type: "variableAccess", identifier: "hello", args: [] },
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("expression evaluation", () => {
test.onTestFinished(() => consoleWarnMock.mockRestore());

// [call ...[:array]]
const expr: Expression = {
const expr: BasicExpression = {
type: "call",
identifier: "call",
args: [
Expand Down Expand Up @@ -208,7 +208,7 @@ describe("expression evaluation", () => {
test.onTestFinished(() => consoleWarnMock.mockRestore());

// { [hello [:world]] }
const expr: Expression = {
const expr: BasicExpression = {
type: "lambda",
expression: {
type: "call",
Expand Down Expand Up @@ -259,7 +259,7 @@ describe("expression evaluation", () => {
test.onTestFinished(() => consoleWarnMock.mockRestore());

// [call { [ret [:world]] }]
const expr: Expression = {
const expr: BasicExpression = {
type: "call",
identifier: "call",
args: [
Expand Down Expand Up @@ -312,7 +312,7 @@ describe("expression evaluation", () => {
test.onTestFinished(() => consoleWarnMock.mockRestore());

// [:var hello world how is it going]
const expr: Expression = {
const expr: BasicExpression = {
type: "variableAccess",
identifier: "var",
args: ["hello", "world", "how", "is", "it", "going"],
Expand Down Expand Up @@ -343,7 +343,7 @@ describe("expression evaluation", () => {
test.onTestFinished(() => consoleWarnMock.mockRestore());

// [:var hello world [how] is it going]
const expr: Expression = {
const expr: BasicExpression = {
type: "variableAccess",
identifier: "var",
args: [
Expand Down Expand Up @@ -384,7 +384,7 @@ describe("expression evaluation", () => {
test.onTestFinished(() => consoleWarnMock.mockRestore());

// [join [map [:students] item { [:item fullName] } ] ", "]
const expr: Expression = {
const expr: BasicExpression = {
type: "call",
identifier: "join",
args: [
Expand Down
6 changes: 3 additions & 3 deletions src/sheet/expression/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Expression } from "./parser";
import { BasicExpression } from "./parser";
import { failure, Result, success } from "./result";

// Rule of thumb when erroring out:
Expand Down Expand Up @@ -28,7 +28,7 @@ export type LambdaFunction<T> = (
) => Result<T>;

export function evaluateExpression(
item: Expression,
item: BasicExpression,
context: { col: number; row: number; callTree: string[] },
lookupFunction: (funcName: string) => TemplaterFunction<any> | undefined,
lookupVariable: (name: string) => any | undefined,
Expand All @@ -55,7 +55,7 @@ export function evaluateExpression(
type CanBeSpread<T> = { spread: boolean; data: T };

function evaluateExpressionInternal(
item: Expression,
item: BasicExpression,
context: { col: number; row: number; callTree: string[] },
lookupFunction: (funcName: string) => TemplaterFunction<any> | undefined,
lookupVariable: (name: string) => any | undefined,
Expand Down
Loading

0 comments on commit 66f5f12

Please sign in to comment.