From 4ed0b385cfcbcb6efb0c738b8c6348f66a84c7b3 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 5 Mar 2021 12:01:57 +0200 Subject: [PATCH] Added new `expect(string)` method for custom messages for panic Also made `expect(SymbolType, Token)` use said new method --- source/tlang/compiler/parser.d | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/tlang/compiler/parser.d b/source/tlang/compiler/parser.d index 20ca98f..ef0a50f 100644 --- a/source/tlang/compiler/parser.d +++ b/source/tlang/compiler/parser.d @@ -25,14 +25,17 @@ public final class Parser /* TODO: Crash program if not */ if (!isFine) { - gprintln("Expected symbol of type " ~ to!(string)(symbol) ~ " but got " ~ to!( - string)(actualType) ~ " with " ~ token.toString(), DebugType.ERROR); - import core.stdc.stdlib; - - exit(0); + expect("Expected symbol of type " ~ to!(string)(symbol) ~ " but got " ~ to!( + string)(actualType) ~ " with " ~ token.toString()); } } + public static void expect(string message) + { + gprintln(message, DebugType.ERROR); + exit(0); + } + this(Token[] tokens) { this.tokens = tokens;