This commit is contained in:
nub31
2025-10-20 20:15:29 +02:00
parent 7697f7b7cc
commit 7a3a461519
10 changed files with 125 additions and 70 deletions

View File

@@ -530,12 +530,21 @@ public sealed class Parser
return expr;
}
private ArrayInitializerSyntax ParseArrayInitializer(int startIndex)
private ExpressionSyntax ParseArrayInitializer(int startIndex)
{
var capacity = ParseExpression();
ExpectSymbol(Symbol.CloseBracket);
var type = ParseType();
return new ArrayInitializerSyntax(GetTokens(startIndex), capacity, type);
if (TryExpectIntLiteral(out var intLiteral))
{
ExpectSymbol(Symbol.CloseBracket);
var type = ParseType();
return new ConstArrayInitializerSyntax(GetTokens(startIndex), Convert.ToInt64(intLiteral.Value, intLiteral.Base), type);
}
else
{
var capacity = ParseExpression();
ExpectSymbol(Symbol.CloseBracket);
var type = ParseType();
return new ArrayInitializerSyntax(GetTokens(startIndex), capacity, type);
}
}
private StructInitializerSyntax ParseStructInitializer(int startIndex)
@@ -707,13 +716,19 @@ public sealed class Parser
{
ExpectSymbol(Symbol.CloseBracket);
var baseType = ParseType();
return new ConstArrayTypeSyntax(GetTokens(startIndex), baseType, int.Parse(intLiteral.Value));
return new ConstArrayTypeSyntax(GetTokens(startIndex), baseType, Convert.ToInt64(intLiteral.Value, intLiteral.Base));
}
else if (TryExpectSymbol(Symbol.QuestionMark))
{
ExpectSymbol(Symbol.CloseBracket);
var baseType = ParseType();
return new ArrayTypeSyntax(GetTokens(startIndex), baseType);
}
else
{
ExpectSymbol(Symbol.CloseBracket);
var baseType = ParseType();
return new ArrayTypeSyntax(GetTokens(startIndex), baseType);
return new SliceTypeSyntax(GetTokens(startIndex), baseType);
}
}