From 9763a85478c98460d98203fb27bbf2bdec9bcbff Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Wed, 17 Mar 2021 10:05:56 +0200 Subject: [PATCH] Expect now throws an exception --- source/tlang/compiler/parser.d | 11 +++++++++-- source/tlang/misc/exceptions.d | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 source/tlang/misc/exceptions.d diff --git a/source/tlang/compiler/parser.d b/source/tlang/compiler/parser.d index 5ea2da8..7eccb49 100644 --- a/source/tlang/compiler/parser.d +++ b/source/tlang/compiler/parser.d @@ -6,6 +6,12 @@ import std.string : isNumeric, cmp; import compiler.symbols; import compiler.lexer : Token; import core.stdc.stdlib; +import misc.exceptions : TError; + +// public final class ParserError : TError +// { + +// } public final class Parser { @@ -39,8 +45,9 @@ public final class Parser */ public static void expect(string message) { - gprintln(message, DebugType.ERROR); - exit(0); /* TODO: Exit code */ /* TODO: Version that returns or asserts for unit tests */ + throw new TError(message); + //gprintln(message, DebugType.ERROR); + //exit(0); /* TODO: Exit code */ /* TODO: Version that returns or asserts for unit tests */ } /** diff --git a/source/tlang/misc/exceptions.d b/source/tlang/misc/exceptions.d new file mode 100644 index 0000000..3ca67a4 --- /dev/null +++ b/source/tlang/misc/exceptions.d @@ -0,0 +1,15 @@ +module misc.exceptions; + +import gogga : generateMessage; + +public class TError : Exception +{ + this(string message) + { + /* Generate eerror message using gogga */ + byte[] messageBytes = generateMessage(message, DebugType.ERROR); + /* TODO: Check the vnode for path of fd 0, dont vt100 is not tty device */ + + super(messageBytes); + } +} \ No newline at end of file