foreach
This commit is contained in:
@@ -263,8 +263,17 @@ public class Parser
|
||||
if (TryExpectKeyword(Keyword.While))
|
||||
{
|
||||
var condition = ParseExpression();
|
||||
var thenBlock = ParseStatement();
|
||||
return new NodeStatementWhile(TokensFrom(startIndex), condition, thenBlock);
|
||||
var block = ParseStatement();
|
||||
return new NodeStatementWhile(TokensFrom(startIndex), condition, block);
|
||||
}
|
||||
|
||||
if (TryExpectKeyword(Keyword.For))
|
||||
{
|
||||
var variableName = ExpectIdent();
|
||||
ExpectKeyword(Keyword.In);
|
||||
var array = ParseExpression();
|
||||
var block = ParseStatement();
|
||||
return new NodeStatementFor(TokensFrom(startIndex), variableName, array, block);
|
||||
}
|
||||
|
||||
if (TryExpectKeyword(Keyword.Match))
|
||||
@@ -363,6 +372,19 @@ public class Parser
|
||||
var target = ParseExpression();
|
||||
expr = new NodeExpressionUnary(TokensFrom(startIndex), target, NodeExpressionUnary.Op.Negate);
|
||||
}
|
||||
else if (TryExpectSymbol(Symbol.OpenSquare))
|
||||
{
|
||||
var values = new List<NodeExpression>();
|
||||
|
||||
while (!TryExpectSymbol(Symbol.CloseSquare))
|
||||
{
|
||||
var value = ParseExpression();
|
||||
values.Add(value);
|
||||
TryExpectSymbol(Symbol.Comma);
|
||||
}
|
||||
|
||||
expr = new NodeExpressionArrayLiteral(TokensFrom(startIndex), values);
|
||||
}
|
||||
else if (TryExpectSymbol(Symbol.OpenCurly))
|
||||
{
|
||||
var initializers = new List<NodeExpressionStructLiteral.Initializer>();
|
||||
@@ -893,6 +915,13 @@ public class NodeStatementWhile(List<Token> tokens, NodeExpression condition, No
|
||||
public NodeStatement Body { get; } = body;
|
||||
}
|
||||
|
||||
public class NodeStatementFor(List<Token> tokens, TokenIdent variableName, NodeExpression array, NodeStatement body) : NodeStatement(tokens)
|
||||
{
|
||||
public TokenIdent VariableName { get; } = variableName;
|
||||
public NodeExpression Array { get; } = array;
|
||||
public NodeStatement Body { get; } = body;
|
||||
}
|
||||
|
||||
public class NodeStatementMatch(List<Token> tokens, NodeExpression target, List<NodeStatementMatch.Case> cases) : NodeStatement(tokens)
|
||||
{
|
||||
public NodeExpression Target { get; } = target;
|
||||
@@ -941,6 +970,11 @@ public class NodeExpressionEnumLiteral(List<Token> tokens, NodeTypeNamed type, N
|
||||
public NodeExpression? Value { get; } = value;
|
||||
}
|
||||
|
||||
public class NodeExpressionArrayLiteral(List<Token> tokens, List<NodeExpression> values) : NodeExpression(tokens)
|
||||
{
|
||||
public List<NodeExpression> Values { get; } = values;
|
||||
}
|
||||
|
||||
public class NodeExpressionStringConstructor(List<Token> tokens, NodeExpression value) : NodeExpression(tokens)
|
||||
{
|
||||
public NodeExpression Value { get; } = value;
|
||||
|
||||
Reference in New Issue
Block a user