This commit is contained in:
nub31
2025-05-26 20:39:41 +02:00
parent dcf62e3e05
commit 3279eb7df5
8 changed files with 145 additions and 107 deletions

View File

@@ -484,17 +484,36 @@ public class Parser
case Symbol.New:
{
var type = ParseType();
Dictionary<string, ExpressionNode> initializers = [];
ExpectSymbol(Symbol.OpenBrace);
while (!TryExpectSymbol(Symbol.CloseBrace))
switch (type)
{
var name = ExpectIdentifier().Value;
ExpectSymbol(Symbol.Assign);
var value = ParseExpression();
initializers.Add(name, value);
}
case NubStructType structType:
{
Dictionary<string, ExpressionNode> initializers = [];
ExpectSymbol(Symbol.OpenBrace);
while (!TryExpectSymbol(Symbol.CloseBrace))
{
var name = ExpectIdentifier().Value;
ExpectSymbol(Symbol.Assign);
var value = ParseExpression();
initializers.Add(name, value);
}
expr = new StructInitializerNode(GetTokensForNode(startIndex), type, initializers);
expr = new StructInitializerNode(GetTokensForNode(startIndex), structType, initializers);
break;
}
case NubArrayType arrayType:
{
throw new NotImplementedException();
}
default:
{
throw new ParseException(Diagnostic
.Error($"Cannot use new keyword on type {type}")
.At(symbolToken)
.Build());
}
}
break;
}
case Symbol.Ampersand: