diff --git a/Upsilon/Parser/Lexer.cs b/Upsilon/Parser/Lexer.cs index 6f2f5d3..819daac 100644 --- a/Upsilon/Parser/Lexer.cs +++ b/Upsilon/Parser/Lexer.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Text; @@ -198,6 +199,11 @@ namespace Upsilon.Parser { return new IdentifierToken(str, start); } + + if (kind == SyntaxKind.ReturnKeyword) + { + return new ReturnSyntaxToken(start, Next == Environment.NewLine[0]); + } return new SyntaxToken(kind, start, str, null); } @@ -212,7 +218,7 @@ namespace Upsilon.Parser if (Current != ' ') stringBuilder.Append(Current); } - while (Next != '\n' && Next != '\0') + while (Next != Environment.NewLine[0] && Next != '\0') { stringBuilder?.Append(Next); _position++; diff --git a/Upsilon/Parser/Parser.cs b/Upsilon/Parser/Parser.cs index 53018e6..b3bfcda 100644 --- a/Upsilon/Parser/Parser.cs +++ b/Upsilon/Parser/Parser.cs @@ -282,9 +282,9 @@ namespace Upsilon.Parser private StatementSyntax ParseReturnStatement() { - var returnToken = MatchToken(SyntaxKind.ReturnKeyword); + var returnToken = (ReturnSyntaxToken)MatchToken(SyntaxKind.ReturnKeyword); ExpressionSyntax expression = null; - if (Current.Kind != SyntaxKind.EndKeyword) + if (Current.Kind != SyntaxKind.EndKeyword && !returnToken.FollowedByLineBreak) expression = ParseExpression(); return new ReturnStatementSyntax(returnToken, expression); } diff --git a/Upsilon/Parser/SyntaxToken.cs b/Upsilon/Parser/SyntaxToken.cs index d34817d..0136799 100644 --- a/Upsilon/Parser/SyntaxToken.cs +++ b/Upsilon/Parser/SyntaxToken.cs @@ -28,4 +28,15 @@ namespace Upsilon.Parser yield break; } } + + public class ReturnSyntaxToken : SyntaxToken + { + public bool FollowedByLineBreak { get; } + + public ReturnSyntaxToken(int position, bool followedByLineBreak) + : base(SyntaxKind.ReturnKeyword, position, "return", null) + { + FollowedByLineBreak = followedByLineBreak; + } + } } \ No newline at end of file