Allow for empty return expressions
This commit is contained in:
parent
cefe48cb4b
commit
062f0f84ad
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue