Remove need for semicolon after return
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Syntax.Parsing;
|
||||
public static class Parser
|
||||
{
|
||||
private static string _namespace = null!;
|
||||
private static NubType? _functionReturnType;
|
||||
private static List<Diagnostic> _diagnostics = [];
|
||||
private static IEnumerable<Token> _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<ExpressionNode>.Empty();
|
||||
if (!TryExpectSymbol(Symbol.Semicolon))
|
||||
if (_functionReturnType is not NubVoidType)
|
||||
{
|
||||
value = ParseExpression();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ public enum Symbol
|
||||
While,
|
||||
Break,
|
||||
Continue,
|
||||
Semicolon,
|
||||
Colon,
|
||||
OpenParen,
|
||||
CloseParen,
|
||||
|
||||
@@ -41,7 +41,6 @@ public static class Tokenizer
|
||||
|
||||
private static readonly Dictionary<char, Symbol> Chars = new()
|
||||
{
|
||||
[';'] = Symbol.Semicolon,
|
||||
[':'] = Symbol.Colon,
|
||||
['('] = Symbol.OpenParen,
|
||||
[')'] = Symbol.CloseParen,
|
||||
|
||||
Reference in New Issue
Block a user