diff --git a/src/compiler/Syntax/Diagnostics/ConsoleColors.cs b/src/compiler/Syntax/Diagnostics/ConsoleColors.cs index 887a2fa..ea4979d 100644 --- a/src/compiler/Syntax/Diagnostics/ConsoleColors.cs +++ b/src/compiler/Syntax/Diagnostics/ConsoleColors.cs @@ -106,7 +106,6 @@ public static class ConsoleColors case Symbol.Caret: case Symbol.Ampersand: return White; - case Symbol.Semicolon: case Symbol.Colon: case Symbol.Comma: case Symbol.Period: diff --git a/src/compiler/Syntax/Parsing/Parser.cs b/src/compiler/Syntax/Parsing/Parser.cs index 93f433c..c97e7ae 100644 --- a/src/compiler/Syntax/Parsing/Parser.cs +++ b/src/compiler/Syntax/Parsing/Parser.cs @@ -10,6 +10,7 @@ namespace Syntax.Parsing; public static class Parser { private static string _namespace = null!; + private static NubType? _functionReturnType; private static List _diagnostics = []; private static IEnumerable _tokens = []; private static int _index; @@ -20,6 +21,7 @@ public static class Parser _namespace = "global"; _diagnostics = []; _index = 0; + _functionReturnType = null; if (TryExpectSymbol(Symbol.Namespace)) { @@ -105,6 +107,7 @@ public static class Parser } var returnType = TryExpectSymbol(Symbol.Colon) ? ParseType() : new NubVoidType(); + _functionReturnType = returnType; var isExtern = modifiers.RemoveAll(x => x.Modifier == Modifier.Extern) > 0; if (isExtern) @@ -371,8 +374,9 @@ public static class Parser private static ReturnNode ParseReturn(int startIndex) { ExpectSymbol(Symbol.Return); + var value = Optional.Empty(); - if (!TryExpectSymbol(Symbol.Semicolon)) + if (_functionReturnType is not NubVoidType) { value = ParseExpression(); } diff --git a/src/compiler/Syntax/Tokenization/SymbolToken.cs b/src/compiler/Syntax/Tokenization/SymbolToken.cs index b1cf578..b898315 100644 --- a/src/compiler/Syntax/Tokenization/SymbolToken.cs +++ b/src/compiler/Syntax/Tokenization/SymbolToken.cs @@ -14,7 +14,6 @@ public enum Symbol While, Break, Continue, - Semicolon, Colon, OpenParen, CloseParen, diff --git a/src/compiler/Syntax/Tokenization/Tokenizer.cs b/src/compiler/Syntax/Tokenization/Tokenizer.cs index 68b3725..aeb0aff 100644 --- a/src/compiler/Syntax/Tokenization/Tokenizer.cs +++ b/src/compiler/Syntax/Tokenization/Tokenizer.cs @@ -41,7 +41,6 @@ public static class Tokenizer private static readonly Dictionary Chars = new() { - [';'] = Symbol.Semicolon, [':'] = Symbol.Colon, ['('] = Symbol.OpenParen, [')'] = Symbol.CloseParen,