From c60b41803cef9329b63bc840b76492a39e2dd575 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 11 Jan 2025 15:48:44 +0200 Subject: [PATCH 1/3] ParserException - Don't consume ` Parser` instance SyntaxError - Don't consume ` Parser` instance Modman - Updated `SyntaxErro` cosntructor call Parser - Update ctor calls to `SyntaxError` --- source/tlang/compiler/modman/modman.d | 2 +- source/tlang/compiler/parsing/core.d | 6 +++--- source/tlang/compiler/parsing/exceptions.d | 9 ++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/source/tlang/compiler/modman/modman.d b/source/tlang/compiler/modman/modman.d index 96c82eee..fae22538 100644 --- a/source/tlang/compiler/modman/modman.d +++ b/source/tlang/compiler/modman/modman.d @@ -467,7 +467,7 @@ public final class ModuleManager if(actualType != expected) { // TODO: Make SyntaxError have a parser-less version for null-safety in the future - throw new SyntaxError(null, expected, got); + throw new SyntaxError(expected, got); } } diff --git a/source/tlang/compiler/parsing/core.d b/source/tlang/compiler/parsing/core.d index 5596f067..b8ee28f6 100644 --- a/source/tlang/compiler/parsing/core.d +++ b/source/tlang/compiler/parsing/core.d @@ -48,7 +48,7 @@ public final class Parser /* TODO: Crash program if not */ if (!isFine) { - throw new SyntaxError(this, symbol, token); + throw new SyntaxError(symbol, token); // expect("Expected symbol of type " ~ to!(string)(symbol) ~ " but got " ~ to!( // string)(actualType) ~ " with " ~ token.toString()); } @@ -65,7 +65,7 @@ public final class Parser { ERROR(message); - throw new ParserException(this, ParserException.ParserErrorType.GENERAL_ERROR, message); + throw new ParserException(ParserException.ParserErrorType.GENERAL_ERROR, message); } /** @@ -1341,7 +1341,7 @@ public final class Parser } catch(ConvException e) { - throw new ParserException(this, ParserException.ParserErrorType.LITERAL_OVERFLOW, "Literal '"~numberLiteralStr~"' would overflow"); + throw new ParserException(ParserException.ParserErrorType.LITERAL_OVERFLOW, "Literal '"~numberLiteralStr~"' would overflow"); } } diff --git a/source/tlang/compiler/parsing/exceptions.d b/source/tlang/compiler/parsing/exceptions.d index 7003e0d9..5287c12a 100644 --- a/source/tlang/compiler/parsing/exceptions.d +++ b/source/tlang/compiler/parsing/exceptions.d @@ -9,18 +9,15 @@ import std.conv : to; public class ParserException : TError { - private Parser parser; - public enum ParserErrorType { GENERAL_ERROR, LITERAL_OVERFLOW } - this(Parser parser, ParserErrorType errType = ParserErrorType.GENERAL_ERROR, string message = "") + this(ParserErrorType errType = ParserErrorType.GENERAL_ERROR, string message = "") { super("ParserException("~to!(string)(errType)~"): "~message); - this.parser = parser; } } @@ -30,14 +27,12 @@ public final class SyntaxError : ParserException private SymbolType provided; private Token providedToken; - this(Parser parser, SymbolType expected, Token providedToken) + this(SymbolType expected, Token providedToken) { this.expected = expected; this.provided = getSymbolType(providedToken); this.providedToken = providedToken; - super(parser); - msg = "Syntax error: Expected "~to!(string)(expected)~" but got "~to!(string)(provided)~", see "~providedToken.toString(); } } \ No newline at end of file From ca60b7400ad04dbda9e4433214abb49940292892 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 11 Jan 2025 16:02:53 +0200 Subject: [PATCH 2/3] ParserException - Don't require an enum anymore - Message text is now mandatory Parser - Use new `ParserException` API SyntaxError - Use new `ParserException` API --- source/tlang/compiler/parsing/core.d | 4 ++-- source/tlang/compiler/parsing/exceptions.d | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/source/tlang/compiler/parsing/core.d b/source/tlang/compiler/parsing/core.d index b8ee28f6..7ee1448f 100644 --- a/source/tlang/compiler/parsing/core.d +++ b/source/tlang/compiler/parsing/core.d @@ -65,7 +65,7 @@ public final class Parser { ERROR(message); - throw new ParserException(ParserException.ParserErrorType.GENERAL_ERROR, message); + throw new ParserException(message); } /** @@ -1341,7 +1341,7 @@ public final class Parser } catch(ConvException e) { - throw new ParserException(ParserException.ParserErrorType.LITERAL_OVERFLOW, "Literal '"~numberLiteralStr~"' would overflow"); + throw new ParserException("Literal '"~numberLiteralStr~"' would overflow"); } } diff --git a/source/tlang/compiler/parsing/exceptions.d b/source/tlang/compiler/parsing/exceptions.d index 5287c12a..57425d28 100644 --- a/source/tlang/compiler/parsing/exceptions.d +++ b/source/tlang/compiler/parsing/exceptions.d @@ -9,15 +9,9 @@ import std.conv : to; public class ParserException : TError { - public enum ParserErrorType + this(string message) { - GENERAL_ERROR, - LITERAL_OVERFLOW - } - - this(ParserErrorType errType = ParserErrorType.GENERAL_ERROR, string message = "") - { - super("ParserException("~to!(string)(errType)~"): "~message); + super("ParserException: "~message); } } @@ -33,6 +27,6 @@ public final class SyntaxError : ParserException this.provided = getSymbolType(providedToken); this.providedToken = providedToken; - msg = "Syntax error: Expected "~to!(string)(expected)~" but got "~to!(string)(provided)~", see "~providedToken.toString(); + super("Syntax error: Expected "~to!(string)(expected)~" but got "~to!(string)(provided)~", see "~providedToken.toString()); } } \ No newline at end of file From 673a683e5fab22bae2dc0c7be4723486544f4de1 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 11 Jan 2025 16:15:52 +0200 Subject: [PATCH 3/3] Parser - Docs --- source/tlang/compiler/parsing/core.d | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/tlang/compiler/parsing/core.d b/source/tlang/compiler/parsing/core.d index 7ee1448f..d31fe1e2 100644 --- a/source/tlang/compiler/parsing/core.d +++ b/source/tlang/compiler/parsing/core.d @@ -1,3 +1,8 @@ +/** + * Core parser implementation + * + * Authors: Tristan Brice Velloza Kildaire (deavmi) + */ module tlang.compiler.parsing.core; import tlang.misc.logging; @@ -14,7 +19,9 @@ import std.string : format; import tlang.compiler.modman; import tlang.compiler.symbols.comments; -// TODO: Technically we could make a core parser etc +/** + * The parser + */ public final class Parser { /**