Revert change to parse

This commit is contained in:
Josh Gross
2023-03-17 11:07:11 -04:00
parent aca7ee3df1
commit 3918c66762
4 changed files with 7 additions and 13 deletions
-3
View File
@@ -81,9 +81,6 @@ export function complete(
extensionFunctions
);
const expr = p.parse();
if (!expr) {
return [];
}
const ev = new Evaluator(expr, context, functions);
const result = ev.evaluate();
-6
View File
@@ -1,14 +1,9 @@
import {Expr} from "./ast";
import * as data from "./data";
import {ExpressionEvaluationError} from "./errors";
import {Evaluator} from "./evaluator";
import {Lexer} from "./lexer";
import {Parser} from "./parser";
function assertDefined(x: Expr | undefined): asserts x is Expr {
expect(x).toBeDefined();
}
describe("evaluator", () => {
const lexAndParse = (input: string) => {
const lexer = new Lexer(input);
@@ -17,7 +12,6 @@ describe("evaluator", () => {
// Parse
const parser = new Parser(result.tokens, ["foo"], []);
const expr = parser.parse();
assertDefined(expr);
return expr;
};
+6 -3
View File
@@ -43,13 +43,16 @@ export class Parser {
};
}
public parse(): Expr | undefined {
public parse(): Expr {
// eslint-disable-next-line prefer-const
let result!: Expr;
// No tokens
if (this.atEnd()) {
return;
return result;
}
const result = this.expression();
result = this.expression();
if (!this.atEnd()) {
throw this.buildError(ErrorType.ErrorUnexpectedSymbol, this.peek());
+1 -1
View File
@@ -119,7 +119,7 @@ describe("x-lang tests", () => {
// Parse
const contextNames = testCase.contexts.pairs().map(x => x.key);
const parser = new Parser(result.tokens, contextNames, []);
let expr: Expr | undefined;
let expr: Expr;
try {
expr = parser.parse();