diff --git a/source/tlang/compiler/parsing/core.d b/source/tlang/compiler/parsing/core.d index 2824227c..545beca6 100644 --- a/source/tlang/compiler/parsing/core.d +++ b/source/tlang/compiler/parsing/core.d @@ -10,15 +10,6 @@ import core.stdc.stdlib; import misc.exceptions : TError; import tlang.compiler.parsing.exceptions; -// public final class ParserError : TError -// { - -// } - - - -bool isUnitTest; - // TODO: Technically we could make a core parser etc public final class Parser { @@ -46,24 +37,18 @@ public final class Parser } } - /** - * Crashes the parser with the given message - */ - public static void expect(string message) + /** + * Crashes the parser with an expectation message + * by throwing a new `ParserException`. + * + * Params: + * message = the expectation message + */ + public void expect(string message) { - //throw new TError(message); gprintln(message, DebugType.ERROR); - if(isUnitTest) - { - throw new TError(message); - assert(false); - } - else - { - throw new TError(message); - //exit(0); /* TODO: Exit code */ /* TODO: Version that returns or asserts for unit tests */ - } + throw new ParserException(this, ParserException.ParserErrorType.GENERAL_ERROR, message); } /** @@ -3130,9 +3115,12 @@ int wrongFunction() assert(false); } - // TODO: Make more specific (see https://deavmi.assigned.network/git/tlang/tlang/issues/147) - catch(TError) + catch(ParserException) { assert(true); } + catch(TError) + { + assert(false); + } } \ No newline at end of file diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 19b7784e..a6603a55 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -78,6 +78,18 @@ public final class TypeChecker return config; } + /** + * Crashes the type checker with an expectation message + * by throwing a new `TypeCheckerException`. + * + * Params: + * message = the expectation message + */ + public void expect(string message) + { + throw new TypeCheckerException(this, TypeCheckerException.TypecheckError.GENERAL_ERROR, message); + } + /** * I guess this should be called rather * when processing assignments but I also @@ -2316,19 +2328,19 @@ public final class TypeChecker } else { - Parser.expect("Cannot inherit from self"); + expect("Cannot inherit from self"); } } /* Error */ else { - Parser.expect("Can only inherit from classes"); + expect("Can only inherit from classes"); } } /* If the entity doesn't exist then it is an error */ else { - Parser.expect("Could not find any entity named " ~ parent); + expect("Could not find any entity named " ~ parent); } } } @@ -2593,7 +2605,7 @@ public final class TypeChecker */ if (resolver.resolveUp(c, clazz.getName()) != clazz) { - Parser.expect("Cannot define class \"" ~ resolver.generateName(modulle, + expect("Cannot define class \"" ~ resolver.generateName(modulle, clazz) ~ "\" as one with same name, \"" ~ resolver.generateName(modulle, resolver.resolveUp(c, clazz.getName())) ~ "\" exists in container \"" ~ resolver.generateName( modulle, containerEntity) ~ "\""); @@ -2608,7 +2620,7 @@ public final class TypeChecker // { if (cmp(containerEntity.getName(), clazz.getName()) == 0) { - Parser.expect("Class \"" ~ resolver.generateName(modulle, + expect("Class \"" ~ resolver.generateName(modulle, clazz) ~ "\" cannot be defined within container with same name, \"" ~ resolver.generateName( modulle, containerEntity) ~ "\""); } diff --git a/source/tlang/compiler/typecheck/dependency/core.d b/source/tlang/compiler/typecheck/dependency/core.d index 9c32529a..0ff00c40 100644 --- a/source/tlang/compiler/typecheck/dependency/core.d +++ b/source/tlang/compiler/typecheck/dependency/core.d @@ -479,6 +479,19 @@ public class DNodeGenerator //generate(); } + /** + * Crashes the dependency generator with an + * expectation message by throwing a new + * `DependencyException`. + * + * Params: + * message = the expectation message + */ + public void expect(string message) + { + throw new DependencyException(DependencyError.GENERAL_ERROR, message); + } + public DNode root; @@ -702,14 +715,14 @@ public class DNodeGenerator } else { - Parser.expect("Only class-type may be used with `new`"); + expect("Only class-type may be used with `new`"); assert(false); } gprintln("Poe naais"); } else { - Parser.expect("Invalid ryp"); + expect("Invalid ryp"); assert(false); } // FunctionCall @@ -817,7 +830,7 @@ public class DNodeGenerator } else { - Parser.expect("Cannot reference variable "~nearestName~" which exists but has not been declared yet"); + expect("Cannot reference variable "~nearestName~" which exists but has not been declared yet"); } @@ -865,7 +878,7 @@ public class DNodeGenerator } else { - Parser.expect("No entity by the name "~nearestName~" exists (at all)"); + expect("No entity by the name "~nearestName~" exists (at all)"); } @@ -960,7 +973,7 @@ public class DNodeGenerator } else { - Parser.expect("Could not acces \""~remainingSegment~"\" as it is not a container"); + expect("Could not acces \""~remainingSegment~"\" as it is not a container"); } } @@ -971,7 +984,7 @@ public class DNodeGenerator */ else { - Parser.expect("Could not find an entity named "~remainingSegment); + expect("Could not find an entity named "~remainingSegment); } } @@ -1391,7 +1404,7 @@ public class DNodeGenerator } else { - Parser.expect("Cannot reference variable "~vAsStdAl.getVariableName()~" which exists but has not been declared yet"); + expect("Cannot reference variable "~vAsStdAl.getVariableName()~" which exists but has not been declared yet"); return null; } } @@ -1791,7 +1804,7 @@ public class DNodeGenerator /* Sanity check */ if(clazz.getModifierType() != InitScope.STATIC) { - Parser.expect("SanityCheck: poolClassStatic(): Cannot pool a non-static class"); + expect("SanityCheck: poolClassStatic(): Cannot pool a non-static class"); // assert(clazz.getModifierType() == InitScope.STATIC); } diff --git a/source/tlang/compiler/typecheck/dependency/exceptions.d b/source/tlang/compiler/typecheck/dependency/exceptions.d index 69714c8b..f742fbfc 100644 --- a/source/tlang/compiler/typecheck/dependency/exceptions.d +++ b/source/tlang/compiler/typecheck/dependency/exceptions.d @@ -8,6 +8,7 @@ public enum DependencyError { NOT_YET_LINEARIZED, ALREADY_LINEARIZED, + GENERAL_ERROR } public final class DependencyException : TError