Add anonymous structs

This commit is contained in:
nub31
2026-02-25 21:21:28 +01:00
parent d771396bd4
commit cb4aeb9c01
6 changed files with 153 additions and 18 deletions

View File

@@ -457,6 +457,21 @@ public class Parser
return new NodeTypeFunc(TokensFrom(startIndex), parameters, returnType);
}
if (TryExpectSymbol(Symbol.OpenCurly))
{
var fields = new List<NodeTypeAnonymousStruct.Field>();
while (!TryExpectSymbol(Symbol.CloseCurly))
{
var name = ExpectIdent();
ExpectSymbol(Symbol.Colon);
var type = ParseType();
fields.Add(new NodeTypeAnonymousStruct.Field(name, type));
}
return new NodeTypeAnonymousStruct(TokensFrom(startIndex), fields);
}
if (TryExpectIdent(out var ident))
{
switch (ident.Ident)
@@ -953,6 +968,17 @@ public class NodeTypeNamed(List<Token> tokens, List<TokenIdent> sections) : Node
public List<TokenIdent> Sections { get; } = sections;
}
public class NodeTypeAnonymousStruct(List<Token> tokens, List<NodeTypeAnonymousStruct.Field> fields) : NodeType(tokens)
{
public List<Field> Fields { get; } = fields;
public class Field(TokenIdent name, NodeType type)
{
public TokenIdent Name { get; } = name;
public NodeType Type { get; } = type;
}
}
public class NodeTypePointer(List<Token> tokens, NodeType to) : NodeType(tokens)
{
public NodeType To { get; } = to;