for in syntax
This commit is contained in:
@@ -241,6 +241,8 @@ public sealed class Parser
|
||||
return ParseIf(startIndex);
|
||||
case Symbol.While:
|
||||
return ParseWhile(startIndex);
|
||||
case Symbol.For:
|
||||
return ParseFor(startIndex);
|
||||
case Symbol.Let:
|
||||
return ParseVariableDeclaration(startIndex);
|
||||
case Symbol.Defer:
|
||||
@@ -330,6 +332,23 @@ public sealed class Parser
|
||||
return new WhileSyntax(GetTokens(startIndex), condition, body);
|
||||
}
|
||||
|
||||
private ForSyntax ParseFor(int startIndex)
|
||||
{
|
||||
var itemName = ExpectIdentifier().Value;
|
||||
string? indexName = null;
|
||||
|
||||
if (TryExpectSymbol(Symbol.Comma))
|
||||
{
|
||||
indexName = ExpectIdentifier().Value;
|
||||
}
|
||||
|
||||
ExpectSymbol(Symbol.In);
|
||||
var target = ParseExpression();
|
||||
var body = ParseBlock();
|
||||
|
||||
return new ForSyntax(GetTokens(startIndex), itemName, indexName, target, body);
|
||||
}
|
||||
|
||||
private ExpressionSyntax ParseExpression(int precedence = 0)
|
||||
{
|
||||
var startIndex = _tokenIndex;
|
||||
|
||||
Reference in New Issue
Block a user