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