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.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -198,6 +199,11 @@ namespace Upsilon.Parser
|
||||||
{
|
{
|
||||||
return new IdentifierToken(str, start);
|
return new IdentifierToken(str, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kind == SyntaxKind.ReturnKeyword)
|
||||||
|
{
|
||||||
|
return new ReturnSyntaxToken(start, Next == Environment.NewLine[0]);
|
||||||
|
}
|
||||||
return new SyntaxToken(kind, start, str, null);
|
return new SyntaxToken(kind, start, str, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +218,7 @@ namespace Upsilon.Parser
|
||||||
if (Current != ' ')
|
if (Current != ' ')
|
||||||
stringBuilder.Append(Current);
|
stringBuilder.Append(Current);
|
||||||
}
|
}
|
||||||
while (Next != '\n' && Next != '\0')
|
while (Next != Environment.NewLine[0] && Next != '\0')
|
||||||
{
|
{
|
||||||
stringBuilder?.Append(Next);
|
stringBuilder?.Append(Next);
|
||||||
_position++;
|
_position++;
|
||||||
|
|
|
@ -282,9 +282,9 @@ namespace Upsilon.Parser
|
||||||
|
|
||||||
private StatementSyntax ParseReturnStatement()
|
private StatementSyntax ParseReturnStatement()
|
||||||
{
|
{
|
||||||
var returnToken = MatchToken(SyntaxKind.ReturnKeyword);
|
var returnToken = (ReturnSyntaxToken)MatchToken(SyntaxKind.ReturnKeyword);
|
||||||
ExpressionSyntax expression = null;
|
ExpressionSyntax expression = null;
|
||||||
if (Current.Kind != SyntaxKind.EndKeyword)
|
if (Current.Kind != SyntaxKind.EndKeyword && !returnToken.FollowedByLineBreak)
|
||||||
expression = ParseExpression();
|
expression = ParseExpression();
|
||||||
return new ReturnStatementSyntax(returnToken, expression);
|
return new ReturnStatementSyntax(returnToken, expression);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,15 @@ namespace Upsilon.Parser
|
||||||
yield break;
|
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