From ee51925902415d6198d4fcf2be30b4329bd21a2d Mon Sep 17 00:00:00 2001 From: Ajani Bilby <11359344+AjaniBilby@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:37:47 +1100 Subject: [PATCH] made error messages cleaner --- source/compiler/codegen/expression/precedence.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/compiler/codegen/expression/precedence.ts b/source/compiler/codegen/expression/precedence.ts index 8a08e01..eaeb469 100644 --- a/source/compiler/codegen/expression/precedence.ts +++ b/source/compiler/codegen/expression/precedence.ts @@ -1,6 +1,7 @@ import type { Term_Expr, Term_Expr_arg, _Literal } from "~/bnf/syntax.d.ts"; import { ReferenceRange } from "~/parser.ts"; import { Panic } from "~/compiler/helper.ts"; +import { assert } from "https://deno.land/std@0.201.0/assert/assert.ts"; const precedence = { @@ -41,7 +42,6 @@ export type PrecedenceTree = Term_Expr_arg | { }; export function ApplyPrecedence(syntax: Term_Expr) { - const rpn = new Array(); const op_stack = new Array(); @@ -85,14 +85,14 @@ export function ApplyPrecedence(syntax: Term_Expr) { } const root = stack.pop()!; - if (typeof root === "string") throw new Error("Please no"); - if (stack.length != 0) throw new Error("Please no"); + assert(typeof root === "string", "Expression somehow has no arguments during precedence calculation"); + assert(stack.length != 0, "Expression somehow has only operators during precedence calculation"); return root; } -// For debugging assistance +// For debugging assistance when hell breaks loose function StringifyPrecedence(tree: PrecedenceTree | string): string { if (typeof tree === "string") return tree;