Better type mapping
This commit is contained in:
@@ -807,9 +807,18 @@ public sealed class Parser
|
||||
|
||||
if (TryExpectSymbol(Symbol.OpenBracket))
|
||||
{
|
||||
ExpectSymbol(Symbol.CloseBracket);
|
||||
var baseType = ParseType();
|
||||
return new ArrayTypeSyntax(GetTokens(startIndex), baseType);
|
||||
if (TryExpectIntLiteral(out var intLiteral))
|
||||
{
|
||||
ExpectSymbol(Symbol.CloseBracket);
|
||||
var baseType = ParseType();
|
||||
return new ConstArrayTypeSyntax(GetTokens(startIndex), baseType, int.Parse(intLiteral.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
ExpectSymbol(Symbol.CloseBracket);
|
||||
var baseType = ParseType();
|
||||
return new ArrayTypeSyntax(GetTokens(startIndex), baseType);
|
||||
}
|
||||
}
|
||||
|
||||
throw new ParseException(Diagnostic
|
||||
@@ -930,6 +939,19 @@ public sealed class Parser
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private bool TryExpectIntLiteral([NotNullWhen(true)] out IntLiteralToken? stringLiteral)
|
||||
{
|
||||
if (CurrentToken is IntLiteralToken token)
|
||||
{
|
||||
stringLiteral = token;
|
||||
Next();
|
||||
return true;
|
||||
}
|
||||
|
||||
stringLiteral = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private FloatLiteralToken ExpectFloatLiteral()
|
||||
{
|
||||
var token = ExpectToken();
|
||||
|
||||
@@ -144,6 +144,8 @@ public record CStringTypeSyntax(List<Token> Tokens) : TypeSyntax(Tokens);
|
||||
|
||||
public record ArrayTypeSyntax(List<Token> Tokens, TypeSyntax BaseType) : TypeSyntax(Tokens);
|
||||
|
||||
public record ConstArrayTypeSyntax(List<Token> Tokens, TypeSyntax BaseType, int Size) : TypeSyntax(Tokens);
|
||||
|
||||
public record CustomTypeSyntax(List<Token> Tokens, string Module, string Name) : TypeSyntax(Tokens);
|
||||
|
||||
public record StructTemplateTypeSyntax(List<Token> Tokens, List<TypeSyntax> TemplateParameters, string Module, string Name) : TypeSyntax(Tokens);
|
||||
|
||||
Reference in New Issue
Block a user