Add anonymous structs
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user