Break several while loop if tokens are not consumed
This commit is contained in:
parent
cae3d7fb53
commit
6bb8139f40
|
@ -102,8 +102,14 @@ namespace Upsilon.Parser
|
|||
private StatementSyntax ParseBlockStatement(SyntaxKind[] endTokens)
|
||||
{
|
||||
var statements = ImmutableArray.CreateBuilder<StatementSyntax>();
|
||||
SyntaxToken current = null;
|
||||
while (!endTokens.Contains(Current.Kind))
|
||||
{
|
||||
if (current == Current)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current = Current;
|
||||
var next = ParseStatement();
|
||||
statements.Add(next);
|
||||
}
|
||||
|
@ -177,7 +183,7 @@ namespace Upsilon.Parser
|
|||
{
|
||||
var identifier = MatchToken(SyntaxKind.Identifier);
|
||||
arr.Add((IdentifierToken) identifier);
|
||||
if (Current.Kind == SyntaxKind.InKeyword)
|
||||
if (Current.Kind == SyntaxKind.InKeyword || Current.Kind == SyntaxKind.EndOfFile)
|
||||
break;
|
||||
MatchToken(SyntaxKind.Comma);
|
||||
}
|
||||
|
@ -196,9 +202,15 @@ namespace Upsilon.Parser
|
|||
var functionToken = MatchToken(SyntaxKind.FunctionKeyword);
|
||||
var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis);
|
||||
var variableBuilder = ImmutableArray.CreateBuilder<IdentifierToken>();
|
||||
IdentifierToken lastIdentifier = null;
|
||||
while (Current.Kind != SyntaxKind.CloseParenthesis)
|
||||
{
|
||||
var variableIdentifier = (IdentifierToken)MatchToken(SyntaxKind.Identifier);
|
||||
if (lastIdentifier == variableIdentifier)
|
||||
{
|
||||
break;
|
||||
}
|
||||
lastIdentifier = variableIdentifier;
|
||||
variableBuilder.Add(variableIdentifier);
|
||||
if (Current.Kind == SyntaxKind.Comma)
|
||||
NextToken();
|
||||
|
@ -221,10 +233,16 @@ namespace Upsilon.Parser
|
|||
var identifier = MatchToken(SyntaxKind.Identifier);
|
||||
var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis);
|
||||
var variableBuilder = ImmutableArray.CreateBuilder<IdentifierToken>();
|
||||
IdentifierToken lastIdentifier = null;
|
||||
while (Current.Kind != SyntaxKind.CloseParenthesis || Current.Kind == SyntaxKind.EndOfFile)
|
||||
{
|
||||
var variableIdentifier = MatchToken(SyntaxKind.Identifier);
|
||||
variableBuilder.Add((IdentifierToken) variableIdentifier);
|
||||
var variableIdentifier =(IdentifierToken) MatchToken(SyntaxKind.Identifier);
|
||||
if (lastIdentifier == variableIdentifier)
|
||||
{
|
||||
break;
|
||||
}
|
||||
lastIdentifier = variableIdentifier;
|
||||
variableBuilder.Add( variableIdentifier);
|
||||
if (Current.Kind == SyntaxKind.Comma)
|
||||
NextToken();
|
||||
}
|
||||
|
@ -275,9 +293,13 @@ namespace Upsilon.Parser
|
|||
|
||||
private ExpressionSyntax HandleComplexExpression(ExpressionSyntax baseExpression)
|
||||
{
|
||||
SyntaxToken current = null;
|
||||
while (Current.Kind == SyntaxKind.OpenBracket || Current.Kind == SyntaxKind.OpenParenthesis ||
|
||||
Current.Kind == SyntaxKind.FullStop)
|
||||
{
|
||||
if (Current == current)
|
||||
break;
|
||||
current = Current;
|
||||
if (Current.Kind == SyntaxKind.OpenBracket)
|
||||
baseExpression = ParseIndexExpression(baseExpression);
|
||||
else if (Current.Kind == SyntaxKind.OpenParenthesis)
|
||||
|
@ -406,8 +428,14 @@ namespace Upsilon.Parser
|
|||
{
|
||||
var openParenthesis = MatchToken(SyntaxKind.OpenParenthesis);
|
||||
var parameters = ImmutableArray.CreateBuilder<ExpressionSyntax>();
|
||||
SyntaxToken current = null;
|
||||
while (Current.Kind != SyntaxKind.CloseParenthesis)
|
||||
{
|
||||
if (Current == current)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current = Current;
|
||||
var exp = ParseExpression();
|
||||
parameters.Add(exp);
|
||||
if (Current.Kind == SyntaxKind.Comma)
|
||||
|
@ -471,10 +499,17 @@ namespace Upsilon.Parser
|
|||
var openBrace = MatchToken(SyntaxKind.OpenBrace);
|
||||
var arrBuilder = ImmutableArray.CreateBuilder<SyntaxNode>();
|
||||
bool lastCommaFound = true;
|
||||
SyntaxToken current = null;
|
||||
while (Current.Kind != SyntaxKind.CloseBrace)
|
||||
{
|
||||
if (!lastCommaFound)
|
||||
break;
|
||||
if (Current == current)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
current = Current;
|
||||
var parsed = ParseStatement();
|
||||
SyntaxNode node = parsed;
|
||||
arrBuilder.Add(node);
|
||||
|
|
Loading…
Reference in New Issue